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.
Fork of digitalInPolling_sample by
Revision 3:ec275829202f, committed 2018-01-25
- Comitter:
- novinfard
- Date:
- Thu Jan 25 17:38:44 2018 +0000
- Parent:
- 2:cd1fe8c29793
- Commit message:
- Initial Commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jan 16 18:02:44 2018 +0000 +++ b/main.cpp Thu Jan 25 17:38:44 2018 +0000 @@ -1,16 +1,12 @@ #include "mbed.h" -// Labs 2: Example program for polling an input -// -------------------------------------------- -// The program uses a thread to poll a digital input -// - The thread monitors the position of the button -// - When the button transitions up and down, a press event is signaled -// - Button bounce is guarded against -// A second thread (the default one) checks for the press event and toggles the LED +// Labs 2: polling and rate change by button DigitalIn b1(PTD0, PullUp); DigitalOut led(LED1); +double rate = 100; + Thread pollT ; // thread to poll volatile int pressEvent = 0 ; // Variabe set by the polling thread @@ -51,13 +47,47 @@ */ int main() { led = 1 ; // Initially off + int cycle = 1; // cycle of 100 waiting + int changeCycle = 2; pollT.start(callback(polling)); while(true) { if (pressEvent) { pressEvent = 0 ; // clear the event variable - led = !led ; + + switch (changeCycle) { + case 2 : + changeCycle = 4 ; + break ; + case 4 : + changeCycle = 6 ; + break ; + case 6 : + changeCycle = 8 ; + break ; + case 8 : + changeCycle = 10 ; + break ; + case 10 : + changeCycle = 2 ; + break ; + } + cycle = 1; } + + + if(cycle == changeCycle) { + if(led == 1) { + led = 0; + } else if (led == 0) { + led = 1; + } + + cycle = 1; // reset the cycle + } else { + cycle = cycle + 1; // go to the next cycle + } + Thread::wait(100) ; } } \ No newline at end of file