KBrat-SSD645-HW-3_2_Q6

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_PWM_simple by Stanley Cohen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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             sprintf(lcdData, "%4.0f", lightData*1000);
00043             LCDMess(lcdData);  
00044             pc.printf("%4.3f\r\n",lightData);
00045             timeToChangeDF = DATATIME;
00046             LEDTimer.reset();
00047         }        
00048     }// emd while
00049 }