#include #define total 233 //define sensitivity, high value for decreases sensitivity, low value increases #define sensor 1 //define number of samples Arduino takes, high value will increase stability while increasing response time #define replay 40 //define debouncing, high value will increase stability while increasing response time int state = HIGH; boolean yes12; boolean previous12 = false; boolean yes11; boolean previous11 = false; boolean yes10; boolean previous10 = false; boolean yes9; boolean previous9 = false; boolean yes8; boolean previous8 = false; boolean yes7; boolean previous7 = false; CapacitiveSensor cs_2_12 = CapacitiveSensor(A1, 5); // 2.2M resistor between pins 2 & 12, pin 2 is send pin, pin 12 is sensor pin CapacitiveSensor cs_2_11 = CapacitiveSensor(A1, 6); // 2.2M resistor between pins 2 & 11, pin 2 is send pin, pin 11 is sensor pin CapacitiveSensor cs_2_10 = CapacitiveSensor(A1, 7); // 2.2M resistor between pins 2 & 10, pin 2 is send pin, pin 10 is sensor pin CapacitiveSensor cs_2_9 = CapacitiveSensor(A1, 8); CapacitiveSensor cs_2_8 = CapacitiveSensor(A1, 9); CapacitiveSensor cs_2_7 = CapacitiveSensor(A1, 10); void setup() { cs_2_12.set_CS_AutocaL_Millis(0xFFFFFFFF); //Calibrate the sensor... cs_2_11.set_CS_AutocaL_Millis(0xFFFFFFFF); cs_2_10.set_CS_AutocaL_Millis(0xFFFFFFFF); cs_2_9.set_CS_AutocaL_Millis(0xFFFFFFFF); cs_2_8.set_CS_AutocaL_Millis(0xFFFFFFFF); cs_2_7.set_CS_AutocaL_Millis(0xFFFFFFFF); Serial.begin(115200); } short int a = 1, a1 = 0, b = 1, b1 = 0, c = 1, c1 = 0, d = 1, d1 = 0, e = 1, e1 = 0, f = 1, f1 = 0, g = 1, g1 = 0, h = 1, h1 = 0, i = 1, i1 = 0, j = 1, j1 = 0; //for debounce purpose void loop() { long total1 = cs_2_12.capacitiveSensor(sensor); long total2 = cs_2_11.capacitiveSensor(sensor); long total3 = cs_2_10.capacitiveSensor(sensor); long total4 = cs_2_9.capacitiveSensor(sensor); long total5 = cs_2_8.capacitiveSensor(sensor); long total6 = cs_2_7.capacitiveSensor(sensor); if (total1 > total) { yes12 = true; } else { yes12 = false; } if (total2 > total) { yes11 = true; } else { yes11 = false; } if (total3 > total) { yes10 = true; } else { yes10 = false; } if (total4 > total) { yes9 = true; } else { yes9 = false; } if (total5 > total) { yes8 = true; } else { yes8 = false; } if (total6 > total) { yes7 = true; } else { yes7 = false; } if (yes12 == true && previous12 == false && e) { if (state == LOW) { state = HIGH; } else state = LOW; a = 0; a1 = 0; // Serial.print(total1); // Serial.print("\t"); Serial.println('e'); } if (yes12 == false && previous12 == false) a1++; else a1 = 0; if (a1 == replay) { a = 1; a1 = 0; } if (yes11 == true && previous11 == false && a) { if (state == LOW) { state = HIGH; } else state = LOW; b = 0; b1 = 0; // Serial.print(total2); // Serial.print("\t"); Serial.println('a'); } if (yes11 == false && previous11 == false) b1++; else b1 = 0; if (b1 == replay) { b = 1; b1 = 0; } if (yes10 == true && previous10 == false && d) { if (state == LOW) { state = HIGH; } else state = LOW; c = 0; c1 = 0; // Serial.print(total3); // Serial.print("\t"); Serial.println('d'); } if (yes10 == false && previous10 == false) c1++; else c1 = 0; if (c1 == replay) { c = 1; c1 = 0; } if (yes9 == true && previous9 == false && g) { if (state == LOW) { state = HIGH; } else state = LOW; d = 0; d1 = 0; // Serial.print(total4); // Serial.print("\t"); Serial.println('g'); } if (yes9 == false && previous9 == false) d1++; else d1 = 0; if (d1 == replay) { d = 1; d1 = 0; } if (yes8 == true && previous8 == false && b) { if (state == LOW) { state = HIGH; } else state = LOW; e = 0; e1 = 0; // Serial.print(total5); // Serial.print("\t"); Serial.println('b'); } if (yes8 == false && previous8 == false) e1++; else e1 = 0; if (e1 == replay) { e = 1; e1 = 0; } if (yes7 == true && previous7 == false && e) { if (state == LOW) { state = HIGH; } else state = LOW; f = 0; f1 = 0; // Serial.print(total6); // Serial.print("\t"); Serial.println('f'); } if (yes7 == false && previous7 == false) f1++; else f1 = 0; if (f1 == replay) { f = 1; f1 = 0; } // digitalWrite(led, state); previous12 = yes12; previous11 = yes11; previous10 = yes10; previous9 = yes9; previous8 = yes8; previous7 = yes7; delay(2); }