璇 李
/
Lab2_PWM_UART
AUP Xi'an Lab2
Revision 0:65e58765adf7, committed 2015-05-21
- Comitter:
- gyth
- Date:
- Thu May 21 02:23:19 2015 +0000
- Commit message:
- AUP Xi'an Lab2
Changed in this revision
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 65e58765adf7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 21 02:23:19 2015 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" + +PwmOut led(D5); +DigitalIn button_up(A2); +DigitalIn button_center(D4); +DigitalIn button_down(A3); +Serial pc(SERIAL_TX, SERIAL_RX); + +double brightness = 1.0; +double brightness_inc = 0.1; + +int main() +{ + int bt_flag = 0; + pc.baud(9600); + pc.printf("Hello PWM!\r\n"); + // 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); + pc.printf("Brightness = %.1f\r\n", 1.0-brightness); + } + wait(0.2); // 200 ms + } +}
diff -r 000000000000 -r 65e58765adf7 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 21 02:23:19 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889 \ No newline at end of file