footboard/footboard.ino

61 lines
1.2 KiB
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 = KEY_LEFT_CTRL;
int buttons[7][6] = {
{'1'},
{'2'},
{'3'},
{'4'},
{'5'},
{'6'},
{'7'}
};
char sequence_length[] = {1, 1, 1, 1, 1, 1, 1};
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < n_buttons; ++i) {
pinMode(button_pins[i], INPUT_PULLUP);
}
Keyboard.begin()
}
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) {
int *sequence = buttons[button_i];
char len = sequence_length[button_i];
if (sequence_length[button_i] == 1) {
if (state == LOW) {
Keyboard.press(modKey);
Keyboard.press(sequence[0]);
} else {
Keyboard.releaseAll();
}
} else if(state == LOW) {
Keyboard.press(modKey);
for (int i = 0; i < len; ++i) {
Keyboard.press(sequence[i]);
Keyboard.release(sequence[i]);
delay(12);
}
Keyboard.releaseAll();
}
}