Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FastIO FastPWM SimpleDMA mbed
Fork of Pinscape_Controller by
Diff: main.cpp
- Revision:
- 12:669df364a565
- Parent:
- 11:bd9da7088e6e
- Child:
- 13:72dda449c3c0
--- a/main.cpp Tue Aug 26 22:24:54 2014 +0000
+++ b/main.cpp Wed Aug 27 00:43:20 2014 +0000
@@ -583,6 +583,9 @@
// button input map array
DigitalIn *buttonDigIn[32];
+// timer for button reports
+static Timer buttonTimer;
+
// initialize the button inputs
void initButtons()
{
@@ -594,6 +597,9 @@
else
buttonDigIn[i] = 0;
}
+
+ // start the button timer
+ buttonTimer.start();
}
@@ -626,7 +632,6 @@
int dt; // time since previous reading
uint32_t b; // button state at this reading
};
- static Timer t; // timer for tracking time between readings
static reading readings[8]; // circular buffer of readings
static int ri = 0; // reading buffer index (next write position)
@@ -634,16 +639,15 @@
reading *r = &readings[ri];
// figure the time since the last reading, and read the raw button state
- r->dt = t.read_ms();
+ r->dt = buttonTimer.read_ms();
uint32_t b = r->b = readButtonsRaw();
// start timing the next interval
- t.start();
- t.reset();
+ buttonTimer.reset();
// AND together readings over 50ms
int ms = 0;
- for (int i = 0 ; i < countof(readings) && ms < 50 ; ++i)
+ for (int i = 1 ; i < countof(readings) && ms < 50 ; ++i)
{
// find the next prior reading, wrapping in the circular buffer
int j = ri - i;
@@ -661,7 +665,7 @@
// advance the write position for next time
ri += 1;
- if (ri > countof(readings))
+ if (ri >= countof(readings))
ri = 0;
// return the debounced result
