
Adjusts the great pinscape controller to work with a cheap linear potentiometer instead of the expensive CCD array
Fork of Pinscape_Controller by
Revision 12:669df364a565, committed 2014-08-27
- Comitter:
- mjr
- Date:
- Wed Aug 27 00:43:20 2014 +0000
- Parent:
- 11:bd9da7088e6e
- Child:
- 13:72dda449c3c0
- Commit message:
- Fixed the indicator light (broken by bug in button reader)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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