Lei Lei
/
AUP_Lab2_PWM_UART
AUP_Lab2_PWM_UART
Fork of Lab2_PWM_UART by
main.cpp
- Committer:
- BrentLei
- Date:
- 2015-10-31
- Revision:
- 4:4afd80834e5c
- Parent:
- 3:5f3417989cab
File content as of revision 4:4afd80834e5c:
#include "mbed.h" PwmOut led(D5); DigitalIn button_up(A2); DigitalIn button_center(D4); DigitalIn button_down(A3); double brightness = 1.0; double brightness_inc = 0.1; int main() { int bt_flag = 0; // Set PWM led.write(brightness); while (1) { bt_flag = 1; if(button_up==1) brightness -= brightness_inc; else if(button_down==1) brightness += brightness_inc; else if(button_center==1) brightness = (brightness>0.5)?1.0:0.0; else bt_flag = 0; if(bt_flag==1) { brightness = (brightness>1.0)?0.0:brightness; brightness = (brightness<0.0)?1.0:brightness; led.write(brightness); } wait(0.2); // 200 ms } }