blink with button select and message to LCD

Dependencies:   SLCD mbed

Fork of blink_kl46z_button by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
scohennm
Date:
Mon Sep 14 14:14:04 2015 +0000
Parent:
1:2688f68df85d
Commit message:
blink with button select and message to LCD

Changed in this revision

SLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 2688f68df85d -r b49e5adf84df SLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Mon Sep 14 14:14:04 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
diff -r 2688f68df85d -r b49e5adf84df main.cpp
--- a/main.cpp	Mon Sep 07 17:30:09 2015 +0000
+++ b/main.cpp	Mon Sep 14 14:14:04 2015 +0000
@@ -1,4 +1,6 @@
 #include "mbed.h"
+#include "SLCD.h"
+
 #define LEDON false
 #define LEDOFF true
 #define BUTDOWN false
@@ -8,9 +10,16 @@
 #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"
+#define LCDCHARLEN 10
+#define NUMMESS 2
+#define LRED "RED"
+#define LGREEN "GREN"
+#define PRED "RED\r\n"
+#define PGREEN "GREEN\r\n"
+#define PROGNAME "blink_kl46z_buttton LCD v1\r\n"
 
 // slightly more interesting blinky 140814 sc
+SLCD slcd; //define LCD display
 
 
 int ledState = LEDON;
@@ -19,17 +28,29 @@
 DigitalOut LEDs[NUMBUTS] = {LED_GREEN, LED_RED};
 Serial pc(USBTX, USBRX);// set up USB as communicationis to Host PC via USB connectons
 
+void LCDMess(char *lMess){
+        slcd.Home();
+        slcd.clear();
+        slcd.printf(lMess);
+}
+
 // --------------------------------
 int main() {
     int i; 
     int currentLED = 0;
+    char rMess[NUMMESS][LCDCHARLEN]={LGREEN, LRED};
+    char pMess[NUMMESS][LCDCHARLEN]={PRED, PGREEN};
     pc.printf(PROGNAME);
+    
+    LCDMess(rMess[currentLED]);
+    pc.printf(pMess[currentLED]);
     while(true) {
-        for (i=0; i<NUMBUTS; i++){
+        for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1
             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
+            // if(buttons[i] == BUTDOWN) {
+            if(!buttons[i]) {
+                 LCDMess(rMess[i]);
+                 pc.printf(pMess[i]); // this means that RED will be blinking
                 currentLED = i;
             }
         }