footboard/footboard.ino

44 lines
923 B
Arduino
Raw Permalink Normal View History

2025-10-25 22:37:29 +01:00
char n_buttons = 7;
char button_pins[] = {0, 1, 2, 3, 4, 5, 6};
char pin_state[] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
char modKey = (char) MODIFIERKEY_CTRL;
2025-10-25 22:37:29 +01:00
int buttons[7] = {KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7};
2025-10-25 22:37:29 +01:00
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < n_buttons; ++i) {
pinMode(button_pins[i], INPUT_PULLUP);
}
}
void loop() {
char state = 0;
for (int i = 0; i < n_buttons; ++i) {
state = digitalRead(button_pins[i]);
if (state != pin_state[i]) {
pin_state[i] = state;
set_button_state(i, state);
}
}
delay(10);
}
void set_button_state(int button_i, char state) {
char key = buttons[button_i];
if (state == LOW) {
Keyboard.set_modifier(MODIFIERKEY_ALT);
Keyboard.set_key1(key);
Keyboard.send_now();
} else {
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
2025-10-25 22:37:29 +01:00
}
}