Eli Menchaca
/
lightsense_kl46z_basic
light sesnsor LEDs
Fork of lightsense_kl46z_basic by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "SLCD.h" 00003 00004 00005 #define PROGNAME "lightsense_kl46z_basic v1\n\r" 00006 #define DATATIME 400 // milliseconds 00007 #define LCDLEN 10 00008 #define LIGHTSENSORPORT PTE22 00009 #define LEDON false 00010 #define LEDOFF true 00011 #define LRED "RED" 00012 #define LGREEN "GREN" 00013 00014 SLCD slcd; //define LCD display globally define 00015 Serial pc(USBTX, USBRX); 00016 Timer LEDTimer; 00017 Timer LIGHTTimer; 00018 00019 bool ledState = LEDON; 00020 00021 void LCDMess(char *lMess){ 00022 slcd.Home(); 00023 slcd.clear(); 00024 slcd.printf(lMess); 00025 } 00026 00027 int main() { 00028 AnalogIn LightSensor(LIGHTSENSORPORT); 00029 float lightData; 00030 char lcdData[LCDLEN]; 00031 00032 int timeToChangeDF = DATATIME; 00033 LEDTimer.start(); 00034 LEDTimer.reset(); 00035 pc.printf(PROGNAME); 00036 00037 PwmOut gled(LED_GREEN); 00038 PwmOut rled(LED_RED); 00039 00040 while(true) { 00041 if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion 00042 lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity 00043 sprintf(lcdData,"%4.3f",lightData); 00044 LCDMess(lcdData); 00045 timeToChangeDF = DATATIME; 00046 gled = 0.0; 00047 rled = 0.0; 00048 LEDTimer.reset(); 00049 } 00050 }// emd while 00051 }
Generated on Sat Aug 27 2022 05:56:09 by 1.7.2