#include #define PIN_BUTTON 15 #define PIN_LEFT 30 #define PIN_RIGHT 31 #define PIN_LED 5 int state_lr = 0; int state_b = 0; int debug = 0; void setup() { pinMode(PIN_BUTTON, INPUT); pinMode(PIN_LEFT, INPUT); pinMode(PIN_RIGHT, INPUT); pinMode(PIN_LED, OUTPUT); if (!digitalRead(PIN_BUTTON)) { // debug mode digitalWrite(PIN_LED, HIGH); Serial.begin(9600); debug = 1; } else { // normal mode Keyboard.begin(); } } void loop() { int state_lr_n; int state_b_n; state_lr_n = (digitalRead(PIN_LEFT)<<1) | digitalRead(PIN_RIGHT); state_b_n = !digitalRead(PIN_BUTTON); if (state_b_n != state_b) { if (debug) { Serial.print("button:"); Serial.println(state_b_n); } else { if (state_b_n) { Keyboard.press(' '); } else { Keyboard.release(' '); } } } if (state_lr_n != state_lr) { if (debug) { Serial.print("state:"); Serial.println(state_lr_n); } else { if ((state_lr_n & ~state_lr) & 0b01) { Keyboard.press(KEY_RIGHT_ARROW); } if ((~state_lr_n & state_lr) & 0b01) { Keyboard.release(KEY_RIGHT_ARROW); } if ((state_lr_n & ~state_lr) & 0b10) { Keyboard.press(KEY_LEFT_ARROW); } if ((~state_lr_n & state_lr) & 0b10) { Keyboard.release(KEY_LEFT_ARROW); } } } state_lr = state_lr_n; state_b = state_b_n; delay(10); }