Skip to content

Commit

Permalink
- debounce input (check every 100ms only)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed Jul 20, 2015
1 parent eb7a710 commit a45339b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions examples/HID/HID_volume/HID_volume.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define ENC_RIGHT_PIN 3
#define ENC_LEFT_PIN 4

#define INPUT_POLL_INTERVAL 100

//#define ANDROID_CENTRAL

BLEHIDPeripheral bleHIDPeripheral = BLEHIDPeripheral(BLE_REQ, BLE_RDY, BLE_RST);
Expand All @@ -24,6 +26,7 @@ BLEMultimedia bleMultimedia;
Encoder encoder(ENC_RIGHT_PIN, ENC_LEFT_PIN);

int buttonState;
unsigned long lastInputPollTime = 0;

void setup() {
Serial.begin(115200);
Expand Down Expand Up @@ -61,9 +64,7 @@ void loop() {
Serial.println(central.address());

while (bleHIDPeripheral.connected()) {
pollButton();

pollEncoder();
pollInputs();
}

// central disconnected
Expand All @@ -72,6 +73,17 @@ void loop() {
}
}

void pollInputs() {
// only poll the input every 100ms
if (millis() - lastInputPollTime > INPUT_POLL_INTERVAL) {
pollButton();

pollEncoder();

lastInputPollTime = millis();
}
}

void pollButton() {
// check the button
int tempButtonState = digitalRead(BUTTON_PIN);
Expand Down Expand Up @@ -102,4 +114,3 @@ void pollEncoder() {
encoder.write(0);
}
}

0 comments on commit a45339b

Please sign in to comment.