Dependencies:   SLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
ceojoe1
Date:
Wed Jan 27 02:15:00 2016 +0000
Commit message:
Ambient Light Sensor Demo;

Changed in this revision

SLCD.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 75c2c5adf52a SLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Wed Jan 27 02:15:00 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
diff -r 000000000000 -r 75c2c5adf52a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 27 02:15:00 2016 +0000
@@ -0,0 +1,61 @@
+#include "mbed.h"
+#include "SLCD.h"
+
+#define PROGNAME "LightSense_K146z_PWM v1\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;
+
+void LCDMess(char *lMess)
+{
+    slcd.Home();
+    slcd.clear();
+    slcd.printf(lMess);
+}
+
+int main()
+{
+    PwmOut greenColor(LED_GREEN);
+    PwmOut redColor(LED_RED);
+    AnalogIn LightSensor(LIGHTSENSORPORT);
+    float lightData;
+    char lcdData[LCDLEN];
+    float max;
+    float min = 1.0; 
+    int timeToChangeDF = DATATIME;
+    // set up tier for next step of Duty Factor timing
+    LEDTimer.start();
+    LEDTimer.reset();
+    pc.printf(PROGNAME);
+    
+    while (true) {
+      if(LEDTimer.read_ms() > timeToChangeDF) { //check for timer
+      lightData = (1.0 - LightSensor.read());
+      /*
+       * IF LIGHT DATA > MAX, 
+         MAX VALUE BECOMES THE CURRENT LIGHT DATA
+      */
+      if (lightData > max)
+      {
+          max = lightData;
+      }
+      if(lightData < min)
+      {
+          min = lightData;
+      }
+      pc.printf("MAX: %4.3f\r\n", max);
+      pc.printf("MIN: %4.3f\r\n", min); 
+      greenColor.write(1.0 - lightData);
+      redColor.write(1.0 - lightData);
+      sprintf(lcdData, "%4.3f", lightData);
+      LCDMess(lcdData);
+      pc.printf("%4.3f\r\n", lightData);
+      timeToChangeDF = DATATIME;
+      LEDTimer.reset();
+    }
+}
+}
\ No newline at end of file
diff -r 000000000000 -r 75c2c5adf52a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 27 02:15:00 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file