Tried to initialize the buttons and slider but couldn't get it to work.

Dependencies:   mbed

Committer:
mturner5
Date:
Mon Sep 19 03:28:41 2016 +0000
Revision:
0:0d6b77c9ae01
basic v2;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mturner5 0:0d6b77c9ae01 1 #include "mbed.h"
mturner5 0:0d6b77c9ae01 2 #include "SLCD.h"
mturner5 0:0d6b77c9ae01 3
mturner5 0:0d6b77c9ae01 4
mturner5 0:0d6b77c9ae01 5 #define PROGNAME "lightsense_kl46z_basic v1\n\r"
mturner5 0:0d6b77c9ae01 6 #define DATATIME 400 // milliseconds
mturner5 0:0d6b77c9ae01 7 #define LCDLEN 10
mturner5 0:0d6b77c9ae01 8 #define LIGHTSENSORPORT PTE22
mturner5 0:0d6b77c9ae01 9 #define NUMBUTS 2
mturner5 0:0d6b77c9ae01 10 #define LBUT PTC12
mturner5 0:0d6b77c9ae01 11 #define RBUT PTC3
mturner5 0:0d6b77c9ae01 12
mturner5 0:0d6b77c9ae01 13
mturner5 0:0d6b77c9ae01 14
mturner5 0:0d6b77c9ae01 15 SLCD slcd; //define LCD display globally define
mturner5 0:0d6b77c9ae01 16 Serial pc(USBTX, USBRX);
mturner5 0:0d6b77c9ae01 17 Timer LEDTimer;
mturner5 0:0d6b77c9ae01 18 DigitalIn buttons[NUMBUTS] = {RBUT, LBUT};
mturner5 0:0d6b77c9ae01 19 DigitalOut LEDs[NUMBUTS] = {LED_GREEN, LED_RED};
mturner5 0:0d6b77c9ae01 20
mturner5 0:0d6b77c9ae01 21 void LCDMess(char *lMess){
mturner5 0:0d6b77c9ae01 22 slcd.Home();
mturner5 0:0d6b77c9ae01 23 slcd.clear();
mturner5 0:0d6b77c9ae01 24 slcd.printf(lMess);
mturner5 0:0d6b77c9ae01 25 }
mturner5 0:0d6b77c9ae01 26
mturner5 0:0d6b77c9ae01 27
mturner5 0:0d6b77c9ae01 28 int main() {
mturner5 0:0d6b77c9ae01 29 AnalogIn LightSensor(LIGHTSENSORPORT);
mturner5 0:0d6b77c9ae01 30 float lightData;
mturner5 0:0d6b77c9ae01 31 char lcdData[LCDLEN];
mturner5 0:0d6b77c9ae01 32 PwmOut gled(LED_GREEN);
mturner5 0:0d6b77c9ae01 33 PwmOut rled(LED_RED);
mturner5 0:0d6b77c9ae01 34
mturner5 0:0d6b77c9ae01 35 int timeToChangeDF = DATATIME;
mturner5 0:0d6b77c9ae01 36 LEDTimer.start();
mturner5 0:0d6b77c9ae01 37 LEDTimer.reset();
mturner5 0:0d6b77c9ae01 38 pc.printf(PROGNAME);
mturner5 0:0d6b77c9ae01 39
mturner5 0:0d6b77c9ae01 40 while(true) {
mturner5 0:0d6b77c9ae01 41 if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion
mturner5 0:0d6b77c9ae01 42 lightData = (1.0 - LightSensor.read_u16()); // show as increasiing with increasing intensity
mturner5 0:0d6b77c9ae01 43 sprintf(lcdData,"%4.3f",lightData);
mturner5 0:0d6b77c9ae01 44 LCDMess(lcdData);
mturner5 0:0d6b77c9ae01 45 gled = 1.0 - lightData;
mturner5 0:0d6b77c9ae01 46 rled = 1.0 - lightData;
mturner5 0:0d6b77c9ae01 47 timeToChangeDF = DATATIME;
mturner5 0:0d6b77c9ae01 48 LEDTimer.reset();
mturner5 0:0d6b77c9ae01 49 }
mturner5 0:0d6b77c9ae01 50 }// emd while
mturner5 0:0d6b77c9ae01 51 }