digitalInPolling_Edwin_Kadavy

Fork of digitalInPolling_sample by William Marsh

Files at this revision

API Documentation at this revision

Comitter:
edwinkad
Date:
Fri Feb 02 21:33:26 2018 +0000
Parent:
2:cd1fe8c29793
Commit message:
...

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r cd1fe8c29793 -r df6605132d72 main.cpp
--- a/main.cpp	Tue Jan 16 18:02:44 2018 +0000
+++ b/main.cpp	Fri Feb 02 21:33:26 2018 +0000
@@ -4,7 +4,7 @@
 // --------------------------------------------
 // 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 
+//   - 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
 
@@ -15,18 +15,19 @@
 volatile int pressEvent = 0 ;  // Variabe set by the polling thread
 
 enum buttonPos { up, down, bounce }; // Button positions
-void polling() {
+void polling()
+{
     buttonPos pos = up ;
     int bcounter = 0 ;
     while (true) {
         switch (pos) {
             case up :
-                if (!b1.read()) {    // now down 
+                if (!b1.read()) {    // now down
                     pressEvent = 1 ;  // transition occurred
                     pos = down ;
                 }
                 break ;
-            case down : 
+            case down :
                 if (b1 == 1) { // no longer down
                     bcounter = 3 ; // wait four cycles
                     pos = bounce ;
@@ -49,14 +50,28 @@
 /*  ---- Main function (default thread) ----
     Note that if this thread completes, nothing else works
  */
-int main() {
+
+
+int main()
+{
     led = 1 ;  // Initially off
     pollT.start(callback(polling));
-
+    int speed=2;
+    int counter=speed;
     while(true) {
         if (pressEvent) {
             pressEvent = 0 ; // clear the event variable
+            if(speed>=10) {
+                speed=2;
+            } else {
+                speed+=2;
+            }
+        }
+        if (counter==0) {
             led = !led ;
+            counter=speed;
+        } else {
+            counter-=2;
         }
         Thread::wait(100) ;
     }