myled

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
redplam
Date:
Tue Apr 08 01:53:51 2014 +0000
Commit message:
myled

Changed in this revision

led.c Show annotated file Show diff for this revision Revisions of this file
led.h 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 f134649523c1 led.c
diff -r 000000000000 -r f134649523c1 led.h
diff -r 000000000000 -r f134649523c1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 08 01:53:51 2014 +0000
@@ -0,0 +1,100 @@
+#include "mbed.h"
+#include "led.h"
+//#include "mbed.h"
+
+PwmOut led_blue(PTA5);
+PwmOut led_green(PTC8);
+PwmOut led_red (PTC9);
+//unsigned int led_period = 1000;
+//unsigned int led_pulsewidth = 50;
+//unsigned int led_step =10;
+//unsigned int pwm_red_led(int brightness);
+//unsigned int pwm_blue_led(int brightness);
+//unsigned int pwm_green_led(int brightness);
+unsigned int led_red_pulsewidth;
+unsigned int led_green_pulsewidth;
+unsigned int led_blue_pulsewidth;
+unsigned int led_period =1000;
+unsigned int led_pulsewidth = 0;
+unsigned int led_step = 10;
+
+unsigned int pwm_blue_led(int brightness )
+{
+    if (brightness==1) {
+        led_blue_pulsewidth=led_blue_pulsewidth+led_step;
+        led_blue.pulsewidth_us(led_blue_pulsewidth);
+    };
+    if (brightness==0) {
+        led_blue_pulsewidth=led_blue_pulsewidth-led_step;
+        led_blue.pulsewidth_us(led_blue_pulsewidth);
+    };
+    return led_blue_pulsewidth;
+}
+unsigned int pwm_green_led(int brightness)
+{
+    if (brightness==1) {
+        led_green_pulsewidth=led_green_pulsewidth+led_step;
+        led_green.pulsewidth_us(led_green_pulsewidth);
+    }
+    if (brightness==0) {
+        led_green_pulsewidth=led_green_pulsewidth-led_step;
+        led_green.pulsewidth_us(led_green_pulsewidth);
+    }
+    return led_green_pulsewidth;
+}
+unsigned int pwm_red_led(int brightness)
+{
+    if (brightness==1) {
+        led_red_pulsewidth=led_red_pulsewidth+led_step;
+        led_red.pulsewidth_us(led_red_pulsewidth);
+    }
+    if (brightness==0) {
+        led_red_pulsewidth=led_red_pulsewidth-led_step;
+        led_red.pulsewidth_us(led_red_pulsewidth);
+    }
+    return led_red_pulsewidth;
+}
+int main(void)
+{
+    while(1) {
+        led_blue.period_us(led_period);
+        led_blue_pulsewidth=led_pulsewidth;
+        for (int i=1; i<=100; i++) {
+            pwm_blue_led(1);
+            wait (0.1);
+        }
+        for (int i=1; i<=100; i++) {
+            pwm_blue_led(0);
+            wait (0.1);
+        }
+        led_blue_pulsewidth=10;    // set to 0
+        pwm_blue_led(0);           // set to 0
+
+        led_red.period_us(led_period);
+        led_red_pulsewidth=led_pulsewidth;
+        for (int i=1; i<=100; i++) {
+            pwm_red_led(1);
+            wait (0.1);
+        }
+        for (int i=1; i<=100; i++) {
+            pwm_red_led(0);
+            wait (0.1);
+        }
+        led_red_pulsewidth=10;    // set to 0
+        pwm_red_led(0);           // set to 0
+        
+        led_green.period_us(led_period);
+        led_green_pulsewidth=led_pulsewidth;
+        for (int i=1; i<=100; i++) {
+            pwm_green_led(1);
+            wait (0.1);
+        }
+        for (int i=1; i<=100; i++) {
+            pwm_green_led(0);
+            wait (0.1);
+        }
+        led_green_pulsewidth=10;    // set to 0
+        pwm_green_led(0);           // set to 0
+    }
+
+}
diff -r 000000000000 -r f134649523c1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Apr 08 01:53:51 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file