#include CapacitiveSensor pads[] = { { 2, 3 }, { 2, 4 }, { 2, 5 }, { 2, 6 }, { 2, 7 }, { 2, 8 }, { 2, 9 }, { 2, 10 }, { 2, 11 }, { 2, 12 }, }; #define array_len(a) (sizeof(a) / sizeof *(a)) void setup() { Serial.begin(9600); Serial.println(); pinMode(13, OUTPUT); } unsigned long last_touch_time[array_len(pads)] = {}; void loop() { unsigned long start = millis(); int last_touched = -1; for (int i = 0; i < array_len(pads); ++i) { long val = pads[i].capacitiveSensor(30); bool current = val > 200; if (current) { if (last_touch_time[i] == 0) { last_touch_time[i] = millis(); } if (last_touched < 0 || last_touch_time[last_touched] < last_touch_time[i]) { last_touched = i; } } else { last_touch_time[i] = 0; } Serial.print(val); Serial.print(" "); } // print each value of the pads the print the last touched pad // and the processing time, separated by space unsigned long processing_time = millis() - start; Serial.print(last_touched); Serial.print(" "); Serial.print(processing_time); Serial.print("\n"); }