Working

Dependencies:   mbed

Fork of led by Plamen Totev

Files at this revision

API Documentation at this revision

Comitter:
umairaftab
Date:
Tue Apr 08 02:18:28 2014 +0000
Parent:
0:f134649523c1
Commit message:
working;

Changed in this revision

led.c Show diff for this revision Revisions of this file
led.h Show diff for this revision Revisions of this file
led_lights.cpp Show annotated file Show diff for this revision Revisions of this file
led_lights.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
pindefs.h Show annotated file Show diff for this revision Revisions of this file
diff -r f134649523c1 -r b074ac22294f led.c
diff -r f134649523c1 -r b074ac22294f led.h
diff -r f134649523c1 -r b074ac22294f led_lights.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led_lights.cpp	Tue Apr 08 02:18:28 2014 +0000
@@ -0,0 +1,86 @@
+#include "mbed.h"
+#include "led_lights.h"
+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;
+}
+
+void led_test(void){
+    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
+}
\ No newline at end of file
diff -r f134649523c1 -r b074ac22294f led_lights.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led_lights.h	Tue Apr 08 02:18:28 2014 +0000
@@ -0,0 +1,21 @@
+extern PwmOut led_blue;
+extern PwmOut led_green;
+extern PwmOut led_red;
+//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);
+extern unsigned int led_red_pulsewidth;
+extern unsigned int led_green_pulsewidth;
+extern unsigned int led_blue_pulsewidth;
+extern unsigned int led_period ;
+extern unsigned int led_pulsewidth;
+extern unsigned int led_step;
+
+
+unsigned int pwm_blue_led(int brightness );
+unsigned int pwm_green_led(int brightness);
+unsigned int pwm_red_led(int brightness);
+void led_test(void);
\ No newline at end of file
diff -r f134649523c1 -r b074ac22294f main.cpp
--- a/main.cpp	Tue Apr 08 01:53:51 2014 +0000
+++ b/main.cpp	Tue Apr 08 02:18:28 2014 +0000
@@ -1,100 +1,12 @@
 #include "mbed.h"
-#include "led.h"
+#include "pindefs.h"
+#include "led_lights.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
+        led_test();
     }
 
 }
diff -r f134649523c1 -r b074ac22294f pindefs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pindefs.h	Tue Apr 08 02:18:28 2014 +0000
@@ -0,0 +1,3 @@
+PwmOut led_blue(PTA5);
+PwmOut led_green(PTC8);
+PwmOut led_red (PTC9);
\ No newline at end of file