KL46Z example for NMHU AAA clas

Dependencies:   SLCD mbed

Fork of blink_kl46z by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
scohennm
Date:
Mon Sep 08 19:42:06 2014 +0000
Parent:
0:e23fffd4b9a7
Commit message:
KL46Z using the loop for ramping LED PWM

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
diff -r e23fffd4b9a7 -r d7c915e8a270 SLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Mon Sep 08 19:42:06 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
diff -r e23fffd4b9a7 -r d7c915e8a270 main.cpp
--- a/main.cpp	Thu Aug 14 21:18:38 2014 +0000
+++ b/main.cpp	Mon Sep 08 19:42:06 2014 +0000
@@ -1,19 +1,47 @@
 #include "mbed.h"
+#include "SLCD.h"
+
 #define LEDON false
 #define LEDOFF true
+#define PWMDWELL 50 // milliseconds
+#define DFDELTA 0.01
+#define PWMTIME 1 // ms (kHxz
+#define LCDLEN 10
 
 // slightly more interesting blinky 140814 sc
+// Change to use PWM
 
-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
+
+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);
+    float workingDelta = DFDELTA;
+    int numSteps;
+    int i;
+    
+    numSteps = (int)(1.0/DFDELTA);
     while(true) {
-        ledState = !ledState; // Flip the general state
-        redColor = ledState;
-        greenColor = !ledState;// flip state but don't store it.
-        wait(blinks[ledState]);
+        for (i = 0; i < numSteps; i++){
+            redColor.write(dutyFactor);
+            greenColor.write(1.0 - dutyFactor);
+            dutyFactor += workingDelta;
+//        if(dutyFactor >= 1.0) workingDelta = -workingDelta;
+//        if(dutyFactor < DFDELTA) workingDelta = DFDELTA; // could be done another way
+            sprintf (lcdData,"%4.3f",dutyFactor);  
+            LCDMess(lcdData);  
+            wait_ms(PWMDWELL);
+        }
+        workingDelta = -workingDelta;
     }
 }
\ No newline at end of file