led light on and off using light sensor

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_basic by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
annalou
Date:
Mon Sep 19 02:37:43 2016 +0000
Parent:
9:f619cdaa7a65
Commit message:
AMartssd341_ledbrightlights

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f619cdaa7a65 -r 4fa8bf6e3ade main.cpp
--- a/main.cpp	Fri Sep 09 19:41:10 2016 +0000
+++ b/main.cpp	Mon Sep 19 02:37:43 2016 +0000
@@ -13,30 +13,37 @@
 Serial pc(USBTX, USBRX);
 Timer LEDTimer;
 
-void LCDMess(char *lMess){
-        slcd.Home();
-        slcd.clear();
-        slcd.printf(lMess);
-} 
+void LCDMess(char *lMess)
+{
+    slcd.Home();
+    slcd.clear();
+    slcd.printf(lMess);
+}
 
 
-int main() {
+int main()
+{
     AnalogIn LightSensor(LIGHTSENSORPORT);
-    float lightData; 
+    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);  
+
+    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);
             timeToChangeDF = DATATIME;
+            pc.printf(lcdData);
+            rled = lightData;
+            gled = lightData;
             LEDTimer.reset();
-        }        
+        }
     }// emd while
 }