reading light sensor and out put between analog and digital

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_basic by AnnaLouise Martinez

Files at this revision

API Documentation at this revision

Comitter:
annalou
Date:
Mon Sep 19 04:07:39 2016 +0000
Parent:
10:4fa8bf6e3ade
Commit message:
AMartSSD341_HW5.2Pt2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4fa8bf6e3ade -r 75596fecb8d5 main.cpp
--- a/main.cpp	Mon Sep 19 02:37:43 2016 +0000
+++ b/main.cpp	Mon Sep 19 04:07:39 2016 +0000
@@ -6,6 +6,9 @@
 #define DATATIME 400 // milliseconds
 #define LCDLEN 10
 #define LIGHTSENSORPORT PTE22
+#define LBUT PTC12  // port addresses for buttons
+#define RBUT PTC3
+
 
 
 
@@ -13,6 +16,8 @@
 Serial pc(USBTX, USBRX);
 Timer LEDTimer;
 
+DigitalIn buttons[2] = {RBUT, LBUT};
+
 void LCDMess(char *lMess)
 {
     slcd.Home();
@@ -28,6 +33,8 @@
     char lcdData[LCDLEN];
     PwmOut gled(LED_GREEN);
     PwmOut rled(LED_RED);
+    unsigned short lightWord;
+    bool lButON = false;
 
     int timeToChangeDF = DATATIME;
     LEDTimer.start();
@@ -40,10 +47,24 @@
             sprintf(lcdData,"%4.3f",lightData);
             LCDMess(lcdData);
             timeToChangeDF = DATATIME;
-            pc.printf(lcdData);
+            //pc.printf(lcdData);
             rled = lightData;
             gled = lightData;
+            
+            //using if to switch between the RAW and Float output
+            if(lButON == true)
+            {
+                lightWord = LightSensor.read_u16();
+                pc.printf("LS => %10d \r\n",  lightWord);
+                lButON = false;
+            }
+            else
+            {
+                lightData = (1.0 - LightSensor.read());
+                pc.printf("ls => %1.3f \r\n", lightData); 
+                lButON = true;   
+            }
             LEDTimer.reset();
         }
-    }// emd while
+    }// end while
 }