modified from original -- NG

Dependencies:   SLCD mbed

Fork of blink_kl46z_button_LCD by Stanley Cohen

Committer:
scohennm
Date:
Mon Sep 07 17:30:09 2015 +0000
Revision:
1:2688f68df85d
Parent:
0:e23fffd4b9a7
Child:
2:b49e5adf84df
Blnky with button for SSD341/541 show logic and pullup on button

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scohennm 0:e23fffd4b9a7 1 #include "mbed.h"
scohennm 0:e23fffd4b9a7 2 #define LEDON false
scohennm 0:e23fffd4b9a7 3 #define LEDOFF true
scohennm 1:2688f68df85d 4 #define BUTDOWN false
scohennm 1:2688f68df85d 5 #define BUTUP true
scohennm 1:2688f68df85d 6 #define NUMBUTS 2
scohennm 1:2688f68df85d 7 #define LBUT PTC12
scohennm 1:2688f68df85d 8 #define RBUT PTC3
scohennm 1:2688f68df85d 9 #define BLINKTIME 0.3
scohennm 1:2688f68df85d 10 #define REDMESS "RED LED is ON\r\n" // adding DR and line feed for terminal line advance
scohennm 1:2688f68df85d 11 #define PROGNAME "blink_kl46z_buttton v1\r\n"
scohennm 0:e23fffd4b9a7 12
scohennm 0:e23fffd4b9a7 13 // slightly more interesting blinky 140814 sc
scohennm 0:e23fffd4b9a7 14
scohennm 1:2688f68df85d 15
scohennm 0:e23fffd4b9a7 16 int ledState = LEDON;
scohennm 1:2688f68df85d 17 int buttonStates[NUMBUTS] = {BUTDOWN,BUTUP};
scohennm 1:2688f68df85d 18 DigitalIn buttons[NUMBUTS] = {RBUT, LBUT};
scohennm 1:2688f68df85d 19 DigitalOut LEDs[NUMBUTS] = {LED_GREEN, LED_RED};
scohennm 1:2688f68df85d 20 Serial pc(USBTX, USBRX);// set up USB as communicationis to Host PC via USB connectons
scohennm 0:e23fffd4b9a7 21
scohennm 1:2688f68df85d 22 // --------------------------------
scohennm 0:e23fffd4b9a7 23 int main() {
scohennm 1:2688f68df85d 24 int i;
scohennm 1:2688f68df85d 25 int currentLED = 0;
scohennm 1:2688f68df85d 26 pc.printf(PROGNAME);
scohennm 0:e23fffd4b9a7 27 while(true) {
scohennm 1:2688f68df85d 28 for (i=0; i<NUMBUTS; i++){
scohennm 1:2688f68df85d 29 LEDs[i] = LEDOFF;
scohennm 1:2688f68df85d 30 if(buttons[i] == BUTDOWN) {
scohennm 1:2688f68df85d 31 // red LED has an index of 1 see line 17
scohennm 1:2688f68df85d 32 if (i == 1) pc.printf(REDMESS); // this means that RED will be blinking
scohennm 1:2688f68df85d 33 currentLED = i;
scohennm 1:2688f68df85d 34 }
scohennm 1:2688f68df85d 35 }
scohennm 1:2688f68df85d 36
scohennm 0:e23fffd4b9a7 37 ledState = !ledState; // Flip the general state
scohennm 1:2688f68df85d 38 LEDs[currentLED] = ledState;
scohennm 1:2688f68df85d 39 wait(BLINKTIME);
scohennm 0:e23fffd4b9a7 40 }
scohennm 0:e23fffd4b9a7 41 }