Lei Lei
/
AUP_Lab4_LCD
AUP_Lab4_LCD
Fork of AUP_Lab2_PWM_UART by
main.cpp@1:08431d9e3d95, 2015-07-07 (annotated)
- Committer:
- BrentLei
- Date:
- Tue Jul 07 23:27:48 2015 +0000
- Revision:
- 1:08431d9e3d95
- Parent:
- 0:65e58765adf7
- Child:
- 2:eac7cbeb9da0
AUP_Lab4_LCD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gyth | 0:65e58765adf7 | 1 | #include "mbed.h" |
BrentLei | 1:08431d9e3d95 | 2 | #include "C12832.h" |
gyth | 0:65e58765adf7 | 3 | |
gyth | 0:65e58765adf7 | 4 | PwmOut led(D5); |
gyth | 0:65e58765adf7 | 5 | DigitalIn button_up(A2); |
gyth | 0:65e58765adf7 | 6 | DigitalIn button_center(D4); |
gyth | 0:65e58765adf7 | 7 | DigitalIn button_down(A3); |
BrentLei | 1:08431d9e3d95 | 8 | C12832 lcd(D11, D13, D12, D7, D10); |
gyth | 0:65e58765adf7 | 9 | |
gyth | 0:65e58765adf7 | 10 | double brightness = 1.0; |
gyth | 0:65e58765adf7 | 11 | double brightness_inc = 0.1; |
gyth | 0:65e58765adf7 | 12 | |
gyth | 0:65e58765adf7 | 13 | int main() |
gyth | 0:65e58765adf7 | 14 | { |
gyth | 0:65e58765adf7 | 15 | int bt_flag = 0; |
BrentLei | 1:08431d9e3d95 | 16 | lcd.cls(); |
BrentLei | 1:08431d9e3d95 | 17 | lcd.locate(0,0); |
BrentLei | 1:08431d9e3d95 | 18 | lcd.printf("Hello PWM!\r\n"); |
gyth | 0:65e58765adf7 | 19 | // Set PWM |
gyth | 0:65e58765adf7 | 20 | led.write(brightness); |
gyth | 0:65e58765adf7 | 21 | |
gyth | 0:65e58765adf7 | 22 | while (1) { |
gyth | 0:65e58765adf7 | 23 | bt_flag = 1; |
gyth | 0:65e58765adf7 | 24 | if(button_up==1) |
gyth | 0:65e58765adf7 | 25 | brightness -= brightness_inc; |
gyth | 0:65e58765adf7 | 26 | else if(button_down==1) |
gyth | 0:65e58765adf7 | 27 | brightness += brightness_inc; |
gyth | 0:65e58765adf7 | 28 | else if(button_center==1) |
gyth | 0:65e58765adf7 | 29 | brightness = (brightness>0.5)?1.0:0.0; |
gyth | 0:65e58765adf7 | 30 | else |
gyth | 0:65e58765adf7 | 31 | bt_flag = 0; |
gyth | 0:65e58765adf7 | 32 | if(bt_flag==1) |
gyth | 0:65e58765adf7 | 33 | { |
gyth | 0:65e58765adf7 | 34 | brightness = (brightness>1.0)?0.0:brightness; |
gyth | 0:65e58765adf7 | 35 | brightness = (brightness<0.0)?1.0:brightness; |
gyth | 0:65e58765adf7 | 36 | led.write(brightness); |
BrentLei | 1:08431d9e3d95 | 37 | lcd.locate(0,0); |
BrentLei | 1:08431d9e3d95 | 38 | lcd.printf("Brightness = %.1f\r\n", 1.0-brightness); |
gyth | 0:65e58765adf7 | 39 | } |
gyth | 0:65e58765adf7 | 40 | wait(0.2); // 200 ms |
gyth | 0:65e58765adf7 | 41 | } |
gyth | 0:65e58765adf7 | 42 | } |