Solutions for the Multi LED experiments for LPC812 MAX

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
embeddedartists
Date:
Fri Nov 22 09:49:35 2013 +0000
Parent:
0:341d9b1d4081
Commit message:
Small fixes

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Nov 22 07:06:57 2013 +0000
+++ b/main.cpp	Fri Nov 22 09:49:35 2013 +0000
@@ -3,7 +3,6 @@
 DigitalIn button1(D0);
 DigitalIn button2(D1);
 DigitalIn button3(D3);
-DigitalOut buzzer(D3);
 
 DigitalOut led1(D8);
 DigitalOut led2(D9);
@@ -36,7 +35,7 @@
         state = (state + 1) % 6;
 
         // Reset all outputs 
-        led1 = led2 = led3 = led4 = led5 = led6;
+        led1 = led2 = led3 = led4 = led5 = led6 = 1;
         
         // Set only the active output
         switch(state) {
@@ -183,6 +182,10 @@
                 // have not waited 5 seconds yet
                 continue;
             }
+        } else {
+            // wait for button to be released
+            while(!button1) {
+            }
         }
         
         // ended up here either because the user pressed the button or 5 seconds have passed
@@ -225,7 +228,7 @@
 {
     bool started = true;
     bool flowdown = true;
-    int speed = 5;
+    int speed = 1;
     int state = 0;
     int waited = 0;
 
@@ -243,15 +246,22 @@
         waited += 10;
         
         // Detect if the sequence should be started/stopped
-        if (started && button3) {
-            started = false;
+        if (!button3) {
+            while(!button3) {
+            }
+            if (started) {
+                started = false;
+                continue;
+            } else {
+                started = true;
+                waited = 0;
+            }
+        }
+        if (!started) {
             continue;
-        } else if (!started && !button3) {
-            started = true;
-            waited = 0;
         }
         
-        // Detect direction change (and wait for user to let go of button
+        // Detect direction change (and wait for user to let go of button)
         if (!button2) {
             flowdown = !flowdown;
             while(!button2) {
@@ -261,18 +271,16 @@
         // Detect speed change (increase one step per button press and reset
         // when max is reached)
         if (!button1) {
-            speed++;
-            if (speed == 11) {
-                speed = 1;
-            }
+            speed = (speed + 4) % 5;
             while(!button1) {
             }
         }
         
         // If we have not waited enough (based on current speed) then wait some more
-        if (waited < (200 * speed)) {
+        if (waited < (500 * speed)) {
             continue;
         }
+        waited = 0;
          
         // Update state/counter based on direction
         if (flowdown) {
@@ -313,9 +321,9 @@
 
 int main()
 {
-    experiment1_alt1(); // one way of controlling the LEDs
-    experiment1_alt2(); // another way of controlling the LEDs
-    experiment1_alt3(); // wait for button press
-    experiment1_alt4(); // wait for button press or timeout
+    //experiment1_alt1(); // one way of controlling the LEDs
+    //experiment1_alt2(); // another way of controlling the LEDs
+    //experiment1_alt3(); // wait for button press
+    //experiment1_alt4(); // wait for button press or timeout
     experiment2();
 }
\ No newline at end of file