HW_5.2_pt2

Dependencies:   SLCD TSI mbed

Fork of lightsense_kl46z_basic by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
sbart
Date:
Mon Sep 19 06:03:21 2016 +0000
Parent:
9:f619cdaa7a65
Commit message:
SBart-SSD341-HW-5.2-pt2

Changed in this revision

TSI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f619cdaa7a65 -r f8c028e50ea4 TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Mon Sep 19 06:03:21 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r f619cdaa7a65 -r f8c028e50ea4 main.cpp
--- a/main.cpp	Fri Sep 09 19:41:10 2016 +0000
+++ b/main.cpp	Mon Sep 19 06:03:21 2016 +0000
@@ -1,17 +1,21 @@
 #include "mbed.h"
 #include "SLCD.h"
-
+#include "TSISensor.h"
 
-#define PROGNAME "lightsense_kl46z_basic v1\n\r"
+#define PROGNAME "sbart_lightsense_kl46z pt2\n\r"
 #define DATATIME 400 // milliseconds
 #define LCDLEN 10
 #define LIGHTSENSORPORT PTE22
 
-
-
 SLCD slcd; //define LCD display globally define
 Serial pc(USBTX, USBRX);
 Timer LEDTimer;
+InterruptIn btnRight(PTC3);
+InterruptIn btnLeft(PTC12);
+//AnalogIn lightInRaw();
+bool bLCDSwitch = true; //When true, display floating point number
+short rawData;
+float tsiData;
 
 void LCDMess(char *lMess){
         slcd.Home();
@@ -19,22 +23,54 @@
         slcd.printf(lMess);
 } 
 
+void btnRightPressed(){
+    bLCDSwitch = true;
+    pc.printf("btnRightPressed()");
+
+}
+
+void btnLeftPressed(){
+    bLCDSwitch = false;
+    pc.printf("btnLeftPressed()");
+}
 
 int main() {
     AnalogIn LightSensor(LIGHTSENSORPORT);
     float lightData; 
     char lcdData[LCDLEN];
-   
+    PwmOut gled(LED_GREEN);
+    PwmOut rled(LED_RED);
+    
+    TSISensor tsi;
+       
     int timeToChangeDF = DATATIME;
     LEDTimer.start();
     LEDTimer.reset();
     pc.printf(PROGNAME);
     
+    btnRight.fall(&btnRightPressed);
+    btnLeft.fall(&btnLeftPressed);
+    
     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);  
+            lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity
+            if(bLCDSwitch == true) {
+                sprintf(lcdData,"%4.3f",lightData);
+                pc.printf(lcdData);
+                pc.printf("\r\n");
+            }
+            else {
+                rawData = LightSensor.read_u16();
+                tsiData = tsi.readPercentage();
+                if(tsiData > .5)
+                    rawData = rawData/10;
+                sprintf(lcdData, "%u", rawData);
+                pc.printf(lcdData);
+                pc.printf("\r\n");
+            }
+            LCDMess(lcdData);
+            gled = lightData;
+            rled = lightData;
             timeToChangeDF = DATATIME;
             LEDTimer.reset();
         }