blink with button select and message to LCD

Dependencies:   SLCD mbed

Fork of blink_kl46z_button by Stanley Cohen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SLCD.h"
00003 
00004 #define LEDON false
00005 #define LEDOFF true
00006 #define BUTDOWN false
00007 #define BUTUP true
00008 #define NUMBUTS 2
00009 #define LBUT PTC12
00010 #define RBUT PTC3
00011 #define BLINKTIME 0.3
00012 #define REDMESS "RED LED is ON\r\n" // adding  DR and line feed for terminal line advance
00013 #define LCDCHARLEN 10
00014 #define NUMMESS 2
00015 #define LRED "RED"
00016 #define LGREEN "GREN"
00017 #define PRED "RED\r\n"
00018 #define PGREEN "GREEN\r\n"
00019 #define PROGNAME "blink_kl46z_buttton LCD v1\r\n"
00020 
00021 // slightly more interesting blinky 140814 sc
00022 SLCD slcd; //define LCD display
00023 
00024 
00025 int ledState = LEDON;
00026 int buttonStates[NUMBUTS] = {BUTDOWN,BUTUP};
00027 DigitalIn buttons[NUMBUTS] = {RBUT, LBUT};
00028 DigitalOut LEDs[NUMBUTS] = {LED_GREEN, LED_RED};
00029 Serial pc(USBTX, USBRX);// set up USB as communicationis to Host PC via USB connectons
00030 
00031 void LCDMess(char *lMess){
00032         slcd.Home();
00033         slcd.clear();
00034         slcd.printf(lMess);
00035 }
00036 
00037 // --------------------------------
00038 int main() {
00039     int i; 
00040     int currentLED = 0;
00041     char rMess[NUMMESS][LCDCHARLEN]={LGREEN, LRED};
00042     char pMess[NUMMESS][LCDCHARLEN]={PRED, PGREEN};
00043     pc.printf(PROGNAME);
00044     
00045     LCDMess(rMess[currentLED]);
00046     pc.printf(pMess[currentLED]);
00047     while(true) {
00048         for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1
00049             LEDs[i] = LEDOFF;      
00050             // if(buttons[i] == BUTDOWN) {
00051             if(!buttons[i]) {
00052                  LCDMess(rMess[i]);
00053                  pc.printf(pMess[i]); // this means that RED will be blinking
00054                 currentLED = i;
00055             }
00056         }
00057                 
00058         ledState = !ledState; // Flip the general state
00059         LEDs[currentLED] = ledState;
00060         wait(BLINKTIME);
00061     }
00062 }