AUP_Lab2_PWM_UART

Dependencies:   mbed

Fork of Lab2_PWM_UART by 璇 李

Committer:
BrentLei
Date:
Sat Oct 31 02:42:41 2015 +0000
Revision:
4:4afd80834e5c
Parent:
3:5f3417989cab
nRF51

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
gyth 0:65e58765adf7 15 // Set PWM
gyth 0:65e58765adf7 16 led.write(brightness);
gyth 0:65e58765adf7 17
gyth 0:65e58765adf7 18 while (1) {
gyth 0:65e58765adf7 19 bt_flag = 1;
gyth 0:65e58765adf7 20 if(button_up==1)
gyth 0:65e58765adf7 21 brightness -= brightness_inc;
gyth 0:65e58765adf7 22 else if(button_down==1)
gyth 0:65e58765adf7 23 brightness += brightness_inc;
gyth 0:65e58765adf7 24 else if(button_center==1)
gyth 0:65e58765adf7 25 brightness = (brightness>0.5)?1.0:0.0;
gyth 0:65e58765adf7 26 else
gyth 0:65e58765adf7 27 bt_flag = 0;
gyth 0:65e58765adf7 28 if(bt_flag==1)
gyth 0:65e58765adf7 29 {
gyth 0:65e58765adf7 30 brightness = (brightness>1.0)?0.0:brightness;
gyth 0:65e58765adf7 31 brightness = (brightness<0.0)?1.0:brightness;
gyth 0:65e58765adf7 32 led.write(brightness);
gyth 0:65e58765adf7 33 }
gyth 0:65e58765adf7 34 wait(0.2); // 200 ms
gyth 0:65e58765adf7 35 }
gyth 0:65e58765adf7 36 }