NMHU SSD 341 sieve demo with light sensor while loop for timer

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_states by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
scohennm
Date:
Fri Sep 05 02:26:47 2014 +0000
Parent:
0:e23fffd4b9a7
Child:
2:c016448d89b2
Commit message:
Use of KL46z PWM LCD and LED's for NMHU 140904

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Fri Sep 05 02:26:47 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
--- a/main.cpp	Thu Aug 14 21:18:38 2014 +0000
+++ b/main.cpp	Fri Sep 05 02:26:47 2014 +0000
@@ -1,19 +1,61 @@
 #include "mbed.h"
+#include "SLCD.h"
+
+// An example of C++ abuse 140904 sc
+//#define PRINTDEBUG
+#define PROGNAME "blink_kl46z_states v1\n\r"
 #define LEDON false
 #define LEDOFF true
-
-// slightly more interesting blinky 140814 sc
+#define PWMDWELL 50 // milliseconds
+#define DFDELTA 0.01
+#define PWMTIME 1 // ms (kHz
+#define LCDLEN 10
+#define RMPUP true
+#define RMPDWN false
+#define NUMSTATES 2
 
-float blinks[]={0.200, 0.700};
-int ledState = LEDON;
-DigitalOut greenColor(LED_GREEN);
-DigitalOut redColor(LED_RED);
+float dutyFactor = 0.0;
+PwmOut greenColor(LED_GREEN);
+PwmOut redColor(LED_RED);
+SLCD slcd; //define LCD display
+float rampDirection[NUMSTATES] = {-DFDELTA, DFDELTA};
+
+Serial pc(USBTX, USBRX);
+
+void LCDMess(char *lMess){
+        slcd.Home();
+        slcd.clear();
+        slcd.printf(lMess);
+} 
 
 int main() {
+    char lcdData[LCDLEN];
+    greenColor.period_ms(PWMTIME); // set the frequency of the pulse train
+    redColor.period_ms(PWMTIME);
+    int rampstate = RMPUP;
+    int numSteps;
+    float workingDelta;
+    int i=0;
+    
+    pc.printf(PROGNAME);
+    
+    workingDelta = rampDirection[rampstate];
+    numSteps = (int)(1.0/workingDelta);
     while(true) {
-        ledState = !ledState; // Flip the general state
-        redColor = ledState;
-        greenColor = !ledState;// flip state but don't store it.
-        wait(blinks[ledState]);
+        i++;      
+        redColor.write(dutyFactor);
+        greenColor.write(1.0 - dutyFactor);
+        dutyFactor += workingDelta;
+        sprintf (lcdData,"%4.3f",dutyFactor);  
+        LCDMess(lcdData);
+#ifdef PRINTDEBUG
+        pc.printf("i= %d dutyfactor = %5.4f workingDelta %5.4f \n\r",  i, dutyFactor, workingDelta); 
+#endif
+        if (!(i % numSteps)){
+            i=0;
+            rampstate = !rampstate;
+            workingDelta = rampDirection[rampstate];
+        }
+        wait_ms(PWMDWELL); 
     }
 }
\ No newline at end of file