#include // pull up library #define N_TOUCH 6 // define touch pads #define THRESHOLD 30 // define sensitivity level int touch_pins[N_TOUCH] = {3, 4, 2, 27, 1, 26}; // numbers that correspond to pads int touch_values[N_TOUCH] = {0, 0, 0, 0, 0, 0}; // value for each touchpad, higher value means more capacitance bool pin_touched_now[N_TOUCH] = {false, false, false, false, false, false}; bool pin_touched_past[N_TOUCH] = {false, false, false, false, false, false}; void update_touch() { // void means return no output int t; // t is how long it takes to touch the pad to charge int t_max = 200; // this ensure the code doesnt get stuck in an infinite loop int p; // temporary variable to hold the pin number being tested for (int i = 0; i < N_TOUCH; i++) { // this is a for loop that starts at i; essentially this code checks the pin number for each pad p = touch_pins[i]; pinMode(p, OUTPUT); // this sets the pin to OUTPUT ( in order to drive signals) and set the pin to LOW so that it starts with 0 volts digitalWriteFast(p, LOW); delayMicroseconds(25); // this delay allows the pin to fully discharge noInterrupts(); // pauses other events pinMode(p, INPUT_PULLUP); // change pin to input with pull-up resistor t = 0; while (!digitalReadFast(p) && t < t_max) { // while loop that checks if the pin has reached HIGH t++; } touch_values[i] = t; interrupts(); pin_touched_past[i] = pin_touched_now[i]; pin_touched_now[i] = touch_values[i] > THRESHOLD; } } void setup() { Serial.begin(115200); Keyboard.begin(); // start HID keyboard mode } void loop() { update_touch(); // Example: Touch pad 0 types "A" when pressed if (pin_touched_now[0] && !pin_touched_past[0]) { Keyboard.write('Tyler Barron'); } // Example: Touch pad 1 types Enter when pressed if (pin_touched_now[1] && !pin_touched_past[1]) { Keyboard.write(KEY_RETURN); } // Optional: debug print values for (int i=0; i