Shane Barton
/
sbart_lightsense_kl46z_pt2
HW_5.2_pt2
Fork of lightsense_kl46z_basic by
Diff: main.cpp
- Revision:
- 10:f8c028e50ea4
- Parent:
- 9:f619cdaa7a65
--- a/main.cpp Fri Sep 09 19:41:10 2016 +0000 +++ b/main.cpp Mon Sep 19 06:03:21 2016 +0000 @@ -1,17 +1,21 @@ #include "mbed.h" #include "SLCD.h" - +#include "TSISensor.h" -#define PROGNAME "lightsense_kl46z_basic v1\n\r" +#define PROGNAME "sbart_lightsense_kl46z pt2\n\r" #define DATATIME 400 // milliseconds #define LCDLEN 10 #define LIGHTSENSORPORT PTE22 - - SLCD slcd; //define LCD display globally define Serial pc(USBTX, USBRX); Timer LEDTimer; +InterruptIn btnRight(PTC3); +InterruptIn btnLeft(PTC12); +//AnalogIn lightInRaw(); +bool bLCDSwitch = true; //When true, display floating point number +short rawData; +float tsiData; void LCDMess(char *lMess){ slcd.Home(); @@ -19,22 +23,54 @@ slcd.printf(lMess); } +void btnRightPressed(){ + bLCDSwitch = true; + pc.printf("btnRightPressed()"); + +} + +void btnLeftPressed(){ + bLCDSwitch = false; + pc.printf("btnLeftPressed()"); +} int main() { AnalogIn LightSensor(LIGHTSENSORPORT); float lightData; char lcdData[LCDLEN]; - + PwmOut gled(LED_GREEN); + PwmOut rled(LED_RED); + + TSISensor tsi; + int timeToChangeDF = DATATIME; LEDTimer.start(); LEDTimer.reset(); pc.printf(PROGNAME); + btnRight.fall(&btnRightPressed); + btnLeft.fall(&btnLeftPressed); + while(true) { if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion - lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity - sprintf(lcdData,"%4.3f",lightData); - LCDMess(lcdData); + lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity + if(bLCDSwitch == true) { + sprintf(lcdData,"%4.3f",lightData); + pc.printf(lcdData); + pc.printf("\r\n"); + } + else { + rawData = LightSensor.read_u16(); + tsiData = tsi.readPercentage(); + if(tsiData > .5) + rawData = rawData/10; + sprintf(lcdData, "%u", rawData); + pc.printf(lcdData); + pc.printf("\r\n"); + } + LCDMess(lcdData); + gled = lightData; + rled = lightData; timeToChangeDF = DATATIME; LEDTimer.reset(); }