Shane Barton
/
sbart_lightsense_kl46z_PWM_simple
SB_HW_3-2
Fork of lightsense_kl46z_PWM_simple 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_PWM v1\n\r" 00006 #define DATATIME 400 // milliseconds 00007 #define LCDLEN 10 00008 #define LIGHTSENSORPORT PTE22 00009 00010 SLCD slcd; //define LCD display globally define 00011 Serial pc(USBTX, USBRX); 00012 Timer LEDTimer; 00013 00014 void LCDMess(char *lMess){ 00015 slcd.Home(); 00016 slcd.clear(); 00017 slcd.printf(lMess); 00018 00019 slcd.DP(0, false); //Disables the decimal point in position 0 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()) * 100; // 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 }// end while 00048 }
Generated on Fri Jul 15 2022 20:08:54 by 1.7.2