I'm using the PunchThrough Bean and trying to build a two button project that has multiple functions. The idea is the user can press button 1 or button 2 for either short or long presses, or they can press both buttons simultaneously for a short or long press. This would give the user up to 6 different functions. Below is my code. I can get button 1 or button 2 press to work, but can't get pressing both to work. Also, I can't figure out how to have a function depending on how long a button sequence was pushed. Any help would be greatly appreciated.
const int btn0 = 2;
const int btn1 = 3;
void setup() {
Bean.enableWakeOnConnect(true);
Bean.enablePairingPin(true);
BeanHid.enable();
pinMode(btn0, INPUT_PULLUP);
pinMode(btn1, INPUT_PULLUP);
}
void loop() {
bool connected = Bean.getConnectionState();
pinMode(btn0, INPUT_PULLUP);
pinMode(btn1, INPUT_PULLUP);
if (connected) {
int btn0State = digitalRead(btn0);
int btn1State = digitalRead(btn1);
if ((btn0State == LOW) && (btn1State == HIGH)) {
Bean.setLed(255, 0, 0);
Serial.print("up");
BeanHid.sendKey(KEY_UP_ARROW);
Bean.sleep(500);
Bean.setLed(0, 0, 0);
}
if ((btn1State == LOW) && (btn0State == HIGH)) {
Bean.setLed(0, 255, 0);
Serial.print("down");
BeanHid.sendKey(KEY_DOWN_ARROW);
Bean.sleep(500);
Bean.setLed(0, 0, 0);
}
if ((btn1State == LOW) && (btn0State == LOW)) {
Bean.setLed(0, 0, 255);
Serial.print("right");
BeanHid.sendKey(KEY_RIGHT_ARROW);
Bean.sleep(500);
Bean.setLed(0, 0, 0);
}
}
}