#include #include const int w = 128, h = 64; const int addr = 0x3C; Adafruit_SSD1306 display(w, h); 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); pinMode(13, OUTPUT); if (!display.begin(SSD1306_SWITCHCAPVCC, addr)) { Serial.println(F("SSD1306 allocation failed")); for (;;); // Don't proceed, loop forever } display.setTextColor(WHITE); display.setTextSize(2); } void loop() { unsigned long start = millis(); bool touched = false; for (int i = 0; i < array_len(pads); ++i) { long val = pads[i].capacitiveSensor(30); Serial.print(i); Serial.print(": "); Serial.print(val); Serial.print("\t"); if (val > 200) { touched = true; break; } } digitalWrite(13, touched); unsigned long processing_time = millis() - start; Serial.println(); Serial.println(processing_time); display.clearDisplay(); display.setCursor(0, 0); display.println(touched ? "Touched!" : "No touch"); display.print("T:"); display.println(processing_time); display.display(); }