Commit 6901ad75 authored by Martin Natano's avatar Martin Natano

debounce

parent 20377810
......@@ -39,8 +39,9 @@ void setup() {
// the loop function runs over and over again forever
void loop() {
uint8_t reportData;
uint8_t debounceBuffer[15];
static uint8_t previousReportData;
int i;
int i, j;
reportData = 0;
......@@ -50,6 +51,28 @@ void loop() {
reportData |= (1 << i);
}
for (i = 14; i > 0; i--) {
debounceBuffer[i] = debounceBuffer[i-1];
}
debounceBuffer[0] = reportData;
reportData = previousReportData;
for (i = 0; i < NBUTTONS; i++) {
int n = 0;
for (j = 0; j < 15; j++) {
if (debounceBuffer[j] & (1 << i))
n ++;
}
if (reportData & (1 << i)) {
if (n == 0)
reportData &= ~(1 << i);
} else {
if (n == 15)
reportData |= (1 << i);
}
}
if (reportData != previousReportData) {
HID().SendReport(0x03, &reportData, sizeof(reportData));
......@@ -61,5 +84,5 @@ void loop() {
previousReportData = reportData;
}
delayMicroseconds(1000);
delayMicroseconds(100);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment