switches and lights

Dependencies:   mbed

Revision:
0:a6003d0979bf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 15 19:13:59 2014 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+// Lab 3
+// This program explores the basic capabilites of the digital I/O on the processor
+// Written by: MIDN 3/C N. Weinhardt, MIDN 3/C J. Kangwijaya, 09/22/14
+//Modified:
+//          9/23/14 MIDN 3/C. Weinhardt. Corrected last if else statement.
+BusOut zed(p5, p6, p7, p8, p11); //data bus for LEDs
+DigitalIn sw4(p16);              // switch for control of LEDs
+DigitalIn sw5 (p17);             // switch for control of LEDs
+int  w1;                         // variable to store switch 4
+int w2;                          // variable to store switch 5
+main()
+{
+    int x;                      // variable to store binary input
+    w1=sw5;                     // variable to store switch 5
+    w2=sw4;                     // variable to store switch 4
+    x=4;                        // displays 0b0100 on LEDs
+    zed=x;                      // read switch into variable
+    while(1) {                  // infinite while loop
+
+        if(w1==1 && w2==1) {    // if sw5 and sw4 are on
+            x=4;                // displays 0b0100 on LEDs
+            zed=x;              // read switch into variable
+
+        } else if (w1==1 &&w2==0) {  // if sw5 is on and sw4 is off
+            x=x/2;                   // x equals the variable divided by 2 to be displayed on the LEDs
+            zed=x;                   // read switch into variable
+            wait(0.5);               // change the value every 0.5 seconds
+        } else if (w1==0 && w2==1) { // if sw5 is off and sw4 is on
+            x=x*2;                   // x equals the variable multiplied by 2 to be displayed on the LEDs
+            zed=x;                   // read switch into variable
+            wait(0.5);               // change the value every 0.5 seconds
+        }
+    }
+
+}
\ No newline at end of file