Mark Turner
/
lightsense_kl46z_basic_v1
Basic fading in and out of leds with light sensor.
Diff: main.cpp
- Revision:
- 0:cf7af2656659
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 19 03:24:58 2016 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "SLCD.h" + + +#define PROGNAME "lightsense_kl46z_basic v1\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; + +void LCDMess(char *lMess){ + slcd.Home(); + slcd.clear(); + slcd.printf(lMess); +} + + +int main() { + AnalogIn LightSensor(LIGHTSENSORPORT); + float lightData; + char lcdData[LCDLEN]; + PwmOut gled(LED_GREEN); + PwmOut rled(LED_RED); + + int timeToChangeDF = DATATIME; + LEDTimer.start(); + LEDTimer.reset(); + pc.printf(PROGNAME); + + 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); + gled = 1.0 - lightData; + rled = 1.0 - lightData; + timeToChangeDF = DATATIME; + LEDTimer.reset(); + } + }// emd while +}