AUP_Lab2_PWM_UART

Dependencies:   mbed

Fork of Lab2_PWM_UART by 璇 李

Committer:
BrentLei
Date:
Wed Jul 29 07:08:34 2015 +0000
Revision:
3:5f3417989cab
Parent:
1:08431d9e3d95
Child:
4:4afd80834e5c
fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gyth 0:65e58765adf7 1 #include "mbed.h"
gyth 0:65e58765adf7 2
gyth 0:65e58765adf7 3 PwmOut led(D5);
gyth 0:65e58765adf7 4 DigitalIn button_up(A2);
gyth 0:65e58765adf7 5 DigitalIn button_center(D4);
gyth 0:65e58765adf7 6 DigitalIn button_down(A3);
gyth 0:65e58765adf7 7
gyth 0:65e58765adf7 8 double brightness = 1.0;
gyth 0:65e58765adf7 9 double brightness_inc = 0.1;
gyth 0:65e58765adf7 10
gyth 0:65e58765adf7 11 int main()
gyth 0:65e58765adf7 12 {
gyth 0:65e58765adf7 13 int bt_flag = 0;
BrentLei 3:5f3417989cab 14
BrentLei 3:5f3417989cab 15 printf("Hello PWM!\r\n");
gyth 0:65e58765adf7 16 // Set PWM
gyth 0:65e58765adf7 17 led.write(brightness);
gyth 0:65e58765adf7 18
gyth 0:65e58765adf7 19 while (1) {
gyth 0:65e58765adf7 20 bt_flag = 1;
gyth 0:65e58765adf7 21 if(button_up==1)
gyth 0:65e58765adf7 22 brightness -= brightness_inc;
gyth 0:65e58765adf7 23 else if(button_down==1)
gyth 0:65e58765adf7 24 brightness += brightness_inc;
gyth 0:65e58765adf7 25 else if(button_center==1)
gyth 0:65e58765adf7 26 brightness = (brightness>0.5)?1.0:0.0;
gyth 0:65e58765adf7 27 else
gyth 0:65e58765adf7 28 bt_flag = 0;
gyth 0:65e58765adf7 29 if(bt_flag==1)
gyth 0:65e58765adf7 30 {
gyth 0:65e58765adf7 31 brightness = (brightness>1.0)?0.0:brightness;
gyth 0:65e58765adf7 32 brightness = (brightness<0.0)?1.0:brightness;
gyth 0:65e58765adf7 33 led.write(brightness);
BrentLei 3:5f3417989cab 34 printf("Brightness = %.1f\r\n", 1.0-brightness);
gyth 0:65e58765adf7 35 }
gyth 0:65e58765adf7 36 wait(0.2); // 200 ms
gyth 0:65e58765adf7 37 }
gyth 0:65e58765adf7 38 }