KBrat-SSD645-HW-1_1

Dependencies:   SLCD TSI mbed

Fork of kl46z_btn_slider_toSerial by Stanley Cohen

Revision:
1:2688f68df85d
Parent:
0:e23fffd4b9a7
Child:
2:b49e5adf84df
--- a/main.cpp	Thu Aug 14 21:18:38 2014 +0000
+++ b/main.cpp	Mon Sep 07 17:30:09 2015 +0000
@@ -1,19 +1,41 @@
 #include "mbed.h"
 #define LEDON false
 #define LEDOFF true
+#define BUTDOWN false
+#define BUTUP true
+#define NUMBUTS 2
+#define LBUT PTC12
+#define RBUT PTC3
+#define BLINKTIME 0.3
+#define REDMESS "RED LED is ON\r\n" // adding  DR and line feed for terminal line advance
+#define PROGNAME "blink_kl46z_buttton v1\r\n"
 
 // slightly more interesting blinky 140814 sc
 
-float blinks[]={0.200, 0.700};
+
 int ledState = LEDON;
-DigitalOut greenColor(LED_GREEN);
-DigitalOut redColor(LED_RED);
+int buttonStates[NUMBUTS] = {BUTDOWN,BUTUP};
+DigitalIn buttons[NUMBUTS] = {RBUT, LBUT};
+DigitalOut LEDs[NUMBUTS] = {LED_GREEN, LED_RED};
+Serial pc(USBTX, USBRX);// set up USB as communicationis to Host PC via USB connectons
 
+// --------------------------------
 int main() {
+    int i; 
+    int currentLED = 0;
+    pc.printf(PROGNAME);
     while(true) {
+        for (i=0; i<NUMBUTS; i++){
+            LEDs[i] = LEDOFF;      
+            if(buttons[i] == BUTDOWN) {
+                // red LED has an index of 1 see line 17
+                if (i == 1) pc.printf(REDMESS); // this means that RED will be blinking
+                currentLED = i;
+            }
+        }
+                
         ledState = !ledState; // Flip the general state
-        redColor = ledState;
-        greenColor = !ledState;// flip state but don't store it.
-        wait(blinks[ledState]);
+        LEDs[currentLED] = ledState;
+        wait(BLINKTIME);
     }
 }
\ No newline at end of file