//# include "Keyboard.h"
// remove keyboard from equation
// https://forum.arduino.cc/t/my-two-key-keyboard-occasionally-freezes-for-a-couple-of-seconds-at-a-time/1034842
#define NUM_BUTTONS 2
#define DEBOUNCE_DELAY_MSEC 30
#define POLLING_INTERVAL_USEC 500
const int buttonPins[2] = {3, 8};
const int buttonOutputs[2] = {122, 120};
unsigned long lastContact[2] = {0, 0};
int previousStates[2] = {HIGH, HIGH};
void setup() {
Serial.begin(115200);
Serial.println("Jello Whirled!\n");
// Declare the buttons as input_pullup
for (int i = 0; i < NUM_BUTTONS; ++i) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
// Keyboard.begin();
}
void loop() {
unsigned long time = millis();
for (int i = 0; i < NUM_BUTTONS; ++i) {
if (time - lastContact[i] < DEBOUNCE_DELAY_MSEC) // too soon to even look?
continue;
// no, so get the state of the button
int buttonState = digitalRead(buttonPins[i]);
if (buttonState != previousStates[i]) { // button has changed!
if (!buttonState) { // button got pressed
// Keyboard.press(buttonOutputs[i]);
Serial.print("press ");
Serial.println(i);
}
else { // button got released
// Keyboard.release(buttonOutputs[i]);
Serial.print("release ");
Serial.println(i);
}
previousStates[i] = buttonState; // remember this button
lastContact[i] = time; // and when it changed
}
}
delayMicroseconds(POLLING_INTERVAL_USEC);
}