Md Golam Tanvir Zim / Mbed OS week02_digitalInPolling_modified
Revision:
4:fb8f64836723
Parent:
3:8d87cbabe37e
--- a/main.cpp	Tue Jan 15 09:47:06 2019 +0000
+++ b/main.cpp	Tue Jan 29 19:58:04 2019 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-
+ 
 // Labs 2: Example program for polling an input
 // --------------------------------------------
 // The program uses a thread to poll a digital input
@@ -7,14 +7,19 @@
 //   - 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
-
+ 
 DigitalIn b1(PTD0, PullUp);
 DigitalOut led(LED1);
 
-Thread pollT ; // thread to poll
+ 
+Thread pollT; // thread to poll
+Thread flashL; //Flash the LED 100ms 
+
 volatile int pressEvent = 0 ;  // Variabe set by the polling thread
+float waiting_period[5] = {0.2, 0.4, 0.6, 0.8, 1.0};
+unsigned int i = 0, count = 0;  
+enum buttonPos { up, down, bounce }; // Button positions
 
-enum buttonPos { up, down, bounce }; // Button positions
 void polling() {
     buttonPos pos = up ;
     int bcounter = 0 ;
@@ -46,18 +51,33 @@
     }
 }
 
+
+
+ 
 /*  ---- Main function (default thread) ----
     Note that if this thread completes, nothing else works
  */
 int main() {
     led = 1 ;  // Initially off
-    pollT.start(callback(polling));
-
+    pollT.start(callback(polling)); 
+ 
     while(true) {
-        if (pressEvent) {
-            pressEvent = 0 ; // clear the event variable
-            led = !led ;
+         //led = !led ;
+         wait(0.1);
+         count++; 
+         if(count >= waiting_period[i]*10) {
+            led = !led; 
+            count = 0 ;
         }
-        Thread::wait(0.1) ;
+         //wait(waiting_period[i]); 
+         if (pressEvent) {
+            //Thread::wait(waiting_period[i]-count*100);
+            //wait(waiting_period[i]-count);
+            i++;  
+            i = i%5;
+            //count = 0;
+            pressEvent = 0 ; // clear the event variable 
+        }
+     //wait(0.1);   
     }
 }
\ No newline at end of file