Use long-hand write on Digital I/O

Dependencies:   mbed SLCD

Fork of blink_kl46z by Stanley Cohen

Revision:
2:24090ed5f981
Parent:
0:e23fffd4b9a7
Child:
3:f445e67012ee
--- a/main.cpp	Thu Aug 14 21:18:38 2014 +0000
+++ b/main.cpp	Wed Sep 03 15:03:30 2014 +0000
@@ -1,19 +1,22 @@
 #include "mbed.h"
 #define LEDON false
 #define LEDOFF true
+#define PWMDWELL 50// milliseconds
+#define DFDELTA 0.01
 
 // 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);
 
 int main() {
     while(true) {
-        ledState = !ledState; // Flip the general state
-        redColor = ledState;
-        greenColor = !ledState;// flip state but don't store it.
-        wait(blinks[ledState]);
+        redColor.write(dutyFactor);
+        greenColor.write(1.0 - dutyFactor);
+        dutyFactor += DFDELTA; 
+        if(dutyFactor >= 1.0) dutyFactor = 0.0;  
+        wait_ms(PWMDWELL);
     }
 }
\ No newline at end of file