ES_SSD541_HW_52b

Dependencies:   SLCD TSI mbed

Fork of lightsense_kl46z_basic by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
eseifert
Date:
Mon Sep 19 12:20:03 2016 +0000
Parent:
9:f619cdaa7a65
Commit message:
ES_SSD541_HW_52b;

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 8f6e61ccc23e TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Mon Sep 19 12:20:03 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r f619cdaa7a65 -r 8f6e61ccc23e main.cpp
--- a/main.cpp	Fri Sep 09 19:41:10 2016 +0000
+++ b/main.cpp	Mon Sep 19 12:20:03 2016 +0000
@@ -1,42 +1,81 @@
 #include "mbed.h"
 #include "SLCD.h"
-
+#include "TSISensor.h"
 
 #define PROGNAME "lightsense_kl46z_basic v1\n\r"
-#define DATATIME 400 // milliseconds
+#define DATATIME 400    // milliseconds
 #define LCDLEN 10
 #define LIGHTSENSORPORT PTE22
-
-
+#define TSILIMIT 0.99
+#define LBTN PTC12  // port addresses for buttons
+#define RBTN PTC3
+#define BUTTONTIME 0.2
+#define NUMBUTS 2
 
 SLCD slcd; //define LCD display globally define
 Serial pc(USBTX, USBRX);
 Timer LEDTimer;
+Timer ButtonTimer;
+TSISensor tsi;
 
-void LCDMess(char *lMess){
-        slcd.Home();
-        slcd.clear();
-        slcd.printf(lMess);
-} 
+float lightData_f;
+float tsidata;
 
+void LCDMess(char *lMess)
+{
+    slcd.Home();
+    slcd.clear();
+    slcd.printf(lMess);
+}
 
-int main() {
+int main()
+{
     AnalogIn LightSensor(LIGHTSENSORPORT);
-    float lightData; 
+    DigitalIn buttons[NUMBUTS] = {LBTN, RBTN};
+
+    unsigned lightData_u;
     char lcdData[LCDLEN];
-   
+    bool showRawData = false;
     int timeToChangeDF = DATATIME;
+    int i = 0;
+
     LEDTimer.start();
     LEDTimer.reset();
+    ButtonTimer.start();
+    ButtonTimer.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);  
+    PwmOut gled(LED_GREEN);
+    PwmOut rled(LED_RED);
+
+    while(true) {
+        tsidata = tsi.readPercentage();
+
+        for (i=0; i<NUMBUTS; i++) { // index will be 0 or 1
+            if(!buttons[i]) {
+                showRawData = i;
+            } // if ! buttons
+        }// for loop to look at buttons
+        ButtonTimer.reset();
+
+        if (LEDTimer.read_ms() > timeToChangeDF) { // check for timer time out transtion
+            lightData_f = (1 - LightSensor.read()); //
+            lightData_u = (LightSensor.read_u16());
+            if(showRawData == true) {
+                sprintf(lcdData,"%4.3f",lightData_f);
+            } else {
+                lightData_u % 100;
+                if(tsidata > .75) {
+                    lightData_u / 10;
+                } else {
+                    lightData_u * 10;
+                }
+                sprintf(lcdData,"%u",lightData_u);
+            }
+            LCDMess(lcdData);
+            gled = lightData_f;
+            rled = lightData_f;
             timeToChangeDF = DATATIME;
             LEDTimer.reset();
-        }        
-    }// emd while
-}
+        }
+    }// end while
+}
\ No newline at end of file