Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lightsense_kl46z_states_nowait by
main.cpp
00001 #include "mbed.h" 00002 #include "SLCD.h" 00003 00004 00005 #define PROGNAME "lightsense_kl46z_PWM v1\n\r" 00006 #define DATATIME 400 // milliseconds 00007 #define LCDLEN 10 00008 #define LIGHTSENSORPORT PTE22 00009 00010 00011 00012 SLCD slcd; //define LCD display globally define 00013 Serial pc(USBTX, USBRX); 00014 Timer LEDTimer; 00015 00016 void LCDMess(char *lMess){ 00017 slcd.Home(); 00018 slcd.clear(); 00019 slcd.printf(lMess); 00020 } 00021 00022 int main() { 00023 PwmOut greenColor(LED_GREEN); 00024 PwmOut redColor(LED_RED); 00025 AnalogIn LightSensor(LIGHTSENSORPORT); 00026 float lightData; 00027 char lcdData[LCDLEN]; 00028 00029 int timeToChangeDF = DATATIME; 00030 // set up timer for next step of Duty Factor timing 00031 LEDTimer.start(); 00032 LEDTimer.reset(); 00033 pc.printf(PROGNAME); 00034 00035 00036 while(true) { 00037 if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion 00038 lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity 00039 greenColor.write(1.0- lightData); 00040 redColor.write(1.0-lightData); 00041 sprintf(lcdData,"%4.3f",lightData); 00042 LCDMess(lcdData); 00043 pc.printf("%4.3f\r\n",lightData); 00044 timeToChangeDF = DATATIME; 00045 LEDTimer.reset(); 00046 } 00047 }// emd while 00048 }
Generated on Mon Jul 18 2022 10:30:58 by
1.7.2
