![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Implemented polling code to check button press and change speed of button flashing.
Fork of digitalInPolling_sample by
Diff: main.cpp
- Revision:
- 3:17c6a539bd7c
- Parent:
- 2:cd1fe8c29793
diff -r cd1fe8c29793 -r 17c6a539bd7c main.cpp --- a/main.cpp Tue Jan 16 18:02:44 2018 +0000 +++ b/main.cpp Thu Feb 01 12:24:02 2018 +0000 @@ -49,15 +49,42 @@ /* ---- Main function (default thread) ---- Note that if this thread completes, nothing else works */ +enum states { flashing, timeToCheck }; // flsh thread states int main() { - led = 1 ; // Initially off + int speed = 200; + states state = flashing; + int cycleCounter = 0; + led = 0; // LED is on by default + pollT.start(callback(polling)); while(true) { - if (pressEvent) { - pressEvent = 0 ; // clear the event variable - led = !led ; + Thread::wait(100); + cycleCounter++; + + if (cycleCounter == 1) { + state = timeToCheck; } - Thread::wait(100) ; + + switch (state) { + case flashing: + if (cycleCounter == speed / 100) { + led = !led; + cycleCounter = 0; + } + break; + case timeToCheck: + if (pressEvent) { + cycleCounter = 0; + pressEvent = 0 ; // clear the event variable + if (speed < 1000) { + speed = speed + 200; + } else { + speed = 200; + } + } + state = flashing; + break; + } } } \ No newline at end of file