footboard/footboard.ino

43 lines
923 B
C++

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;
int buttons[7] = {KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7};
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();
}
}