Akhil Nair
/
Lab2polling
lab 2 part 1
Revision 4:cfd889aca1e1, committed 2019-02-07
- Comitter:
- anair12345
- Date:
- Thu Feb 07 09:49:19 2019 +0000
- Parent:
- 3:8d87cbabe37e
- Commit message:
- lab2 ex1 final version
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8d87cbabe37e -r cfd889aca1e1 main.cpp --- a/main.cpp Tue Jan 15 09:47:06 2019 +0000 +++ b/main.cpp Thu Feb 07 09:49:19 2019 +0000 @@ -13,7 +13,10 @@ Thread pollT ; // thread to poll volatile int pressEvent = 0 ; // Variabe set by the polling thread +//int noofcycles = 1 ; +//int waittime = 0.1 ; +int waittime [5] = { 2,4,6,8,10 }; enum buttonPos { up, down, bounce }; // Button positions void polling() { buttonPos pos = up ; @@ -52,12 +55,24 @@ int main() { led = 1 ; // Initially off pollT.start(callback(polling)); - + int i = 0 ; + int count = waittime[i]; while(true) { + wait(0.1); if (pressEvent) { pressEvent = 0 ; // clear the event variable - led = !led ; + i = (i+1)%5; + count = waittime[i]; } - Thread::wait(0.1) ; + else{ + if(count!=0){ + count-- ; + } + else if(count == 0){ + led = !led ; + count = waittime[i]; + } + } + } } \ No newline at end of file