polling fix for lab 2 assessed

Fork of digitalInPolling_sample by William Marsh

Files at this revision

API Documentation at this revision

Comitter:
dhenis
Date:
Fri Feb 02 21:41:51 2018 +0000
Parent:
2:cd1fe8c29793
Commit message:
polling lab2

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	Fri Feb 02 21:41:51 2018 +0000
@@ -9,25 +9,26 @@
 // A second thread (the default one) checks for the press event and toggles the LED
 
 DigitalIn b1(PTD0, PullUp);
-DigitalOut led(LED1);
+DigitalOut  yled(LED1);
 
 Thread pollT ; // thread to poll
 volatile int pressEvent = 0 ;  // Variabe set by the polling thread
 
-enum buttonPos { up, down, bounce }; // Button positions
+enum buttonPos { up, down, bounce }; // Button positions // three options of button position
+
 void polling() {
-    buttonPos pos = up ;
+    buttonPos pos = up ;// initial position
     int bcounter = 0 ;
     while (true) {
         switch (pos) {
             case up :
                 if (!b1.read()) {    // now down 
                     pressEvent = 1 ;  // transition occurred
-                    pos = down ;
+                    pos = down ; // action and update position
                 }
                 break ;
             case down : 
-                if (b1 == 1) { // no longer down
+                if (b1 == 1) { // no longer down. what the default value of b1?- > it depends and doesnt have initial value
                     bcounter = 3 ; // wait four cycles
                     pos = bounce ;
                 }
@@ -52,12 +53,26 @@
 int main() {
     led = 1 ;  // Initially off
     pollT.start(callback(polling));
+    int speed = 200; // global variable
+
 
     while(true) {
-        if (pressEvent) {
+        if (pressEvent) { // main event
             pressEvent = 0 ; // clear the event variable
-            led = !led ;
+             
+           // led = !led ;
+//            Thread::wait(100) ; // time to apply
+//            
+            speed += 200;
+            
+            if(speed>1000){
+                speed =200;
+            }
         }
-        Thread::wait(100) ;
+        
+        Thread::wait(speed) ;
+        led = !led ;
+        
+//        
     }
 }
\ No newline at end of file