Umair Aftab
/
led_pl
Working
Fork of led by
led_lights.cpp
- Committer:
- umairaftab
- Date:
- 2014-04-08
- Revision:
- 1:b074ac22294f
File content as of revision 1:b074ac22294f:
#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 }