Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of blink_kl46z_button_LCD by
main.cpp@2:b49e5adf84df, 2015-09-14 (annotated)
- Committer:
- scohennm
- Date:
- Mon Sep 14 14:14:04 2015 +0000
- Revision:
- 2:b49e5adf84df
- Parent:
- 1:2688f68df85d
- Child:
- 3:fc189dd7ac64
blink with button select and message to LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scohennm | 0:e23fffd4b9a7 | 1 | #include "mbed.h" |
scohennm | 2:b49e5adf84df | 2 | #include "SLCD.h" |
scohennm | 2:b49e5adf84df | 3 | |
scohennm | 0:e23fffd4b9a7 | 4 | #define LEDON false |
scohennm | 0:e23fffd4b9a7 | 5 | #define LEDOFF true |
scohennm | 1:2688f68df85d | 6 | #define BUTDOWN false |
scohennm | 1:2688f68df85d | 7 | #define BUTUP true |
scohennm | 1:2688f68df85d | 8 | #define NUMBUTS 2 |
scohennm | 1:2688f68df85d | 9 | #define LBUT PTC12 |
scohennm | 1:2688f68df85d | 10 | #define RBUT PTC3 |
scohennm | 1:2688f68df85d | 11 | #define BLINKTIME 0.3 |
scohennm | 1:2688f68df85d | 12 | #define REDMESS "RED LED is ON\r\n" // adding DR and line feed for terminal line advance |
scohennm | 2:b49e5adf84df | 13 | #define LCDCHARLEN 10 |
scohennm | 2:b49e5adf84df | 14 | #define NUMMESS 2 |
scohennm | 2:b49e5adf84df | 15 | #define LRED "RED" |
scohennm | 2:b49e5adf84df | 16 | #define LGREEN "GREN" |
scohennm | 2:b49e5adf84df | 17 | #define PRED "RED\r\n" |
scohennm | 2:b49e5adf84df | 18 | #define PGREEN "GREEN\r\n" |
scohennm | 2:b49e5adf84df | 19 | #define PROGNAME "blink_kl46z_buttton LCD v1\r\n" |
scohennm | 0:e23fffd4b9a7 | 20 | |
scohennm | 0:e23fffd4b9a7 | 21 | // slightly more interesting blinky 140814 sc |
scohennm | 2:b49e5adf84df | 22 | SLCD slcd; //define LCD display |
scohennm | 0:e23fffd4b9a7 | 23 | |
scohennm | 1:2688f68df85d | 24 | |
scohennm | 0:e23fffd4b9a7 | 25 | int ledState = LEDON; |
scohennm | 1:2688f68df85d | 26 | int buttonStates[NUMBUTS] = {BUTDOWN,BUTUP}; |
scohennm | 1:2688f68df85d | 27 | DigitalIn buttons[NUMBUTS] = {RBUT, LBUT}; |
scohennm | 1:2688f68df85d | 28 | DigitalOut LEDs[NUMBUTS] = {LED_GREEN, LED_RED}; |
scohennm | 1:2688f68df85d | 29 | Serial pc(USBTX, USBRX);// set up USB as communicationis to Host PC via USB connectons |
scohennm | 0:e23fffd4b9a7 | 30 | |
scohennm | 2:b49e5adf84df | 31 | void LCDMess(char *lMess){ |
scohennm | 2:b49e5adf84df | 32 | slcd.Home(); |
scohennm | 2:b49e5adf84df | 33 | slcd.clear(); |
scohennm | 2:b49e5adf84df | 34 | slcd.printf(lMess); |
scohennm | 2:b49e5adf84df | 35 | } |
scohennm | 2:b49e5adf84df | 36 | |
scohennm | 1:2688f68df85d | 37 | // -------------------------------- |
scohennm | 0:e23fffd4b9a7 | 38 | int main() { |
scohennm | 1:2688f68df85d | 39 | int i; |
scohennm | 1:2688f68df85d | 40 | int currentLED = 0; |
scohennm | 2:b49e5adf84df | 41 | char rMess[NUMMESS][LCDCHARLEN]={LGREEN, LRED}; |
scohennm | 2:b49e5adf84df | 42 | char pMess[NUMMESS][LCDCHARLEN]={PRED, PGREEN}; |
scohennm | 1:2688f68df85d | 43 | pc.printf(PROGNAME); |
scohennm | 2:b49e5adf84df | 44 | |
scohennm | 2:b49e5adf84df | 45 | LCDMess(rMess[currentLED]); |
scohennm | 2:b49e5adf84df | 46 | pc.printf(pMess[currentLED]); |
scohennm | 0:e23fffd4b9a7 | 47 | while(true) { |
scohennm | 2:b49e5adf84df | 48 | for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1 |
scohennm | 1:2688f68df85d | 49 | LEDs[i] = LEDOFF; |
scohennm | 2:b49e5adf84df | 50 | // if(buttons[i] == BUTDOWN) { |
scohennm | 2:b49e5adf84df | 51 | if(!buttons[i]) { |
scohennm | 2:b49e5adf84df | 52 | LCDMess(rMess[i]); |
scohennm | 2:b49e5adf84df | 53 | pc.printf(pMess[i]); // this means that RED will be blinking |
scohennm | 1:2688f68df85d | 54 | currentLED = i; |
scohennm | 1:2688f68df85d | 55 | } |
scohennm | 1:2688f68df85d | 56 | } |
scohennm | 1:2688f68df85d | 57 | |
scohennm | 0:e23fffd4b9a7 | 58 | ledState = !ledState; // Flip the general state |
scohennm | 1:2688f68df85d | 59 | LEDs[currentLED] = ledState; |
scohennm | 1:2688f68df85d | 60 | wait(BLINKTIME); |
scohennm | 0:e23fffd4b9a7 | 61 | } |
scohennm | 0:e23fffd4b9a7 | 62 | } |