Lei Lei
/
AUP_Lab4_LCD
AUP_Lab4_LCD
Fork of AUP_Lab2_PWM_UART by
main.cpp@2:eac7cbeb9da0, 2015-07-08 (annotated)
- Committer:
- BrentLei
- Date:
- Wed Jul 08 00:04:40 2015 +0000
- Revision:
- 2:eac7cbeb9da0
- Parent:
- 1:08431d9e3d95
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gyth | 0:65e58765adf7 | 1 | #include "mbed.h" |
BrentLei | 2:eac7cbeb9da0 | 2 | |
BrentLei | 2:eac7cbeb9da0 | 3 | // 添加液晶屏类库 |
BrentLei | 1:08431d9e3d95 | 4 | #include "C12832.h" |
gyth | 0:65e58765adf7 | 5 | |
gyth | 0:65e58765adf7 | 6 | PwmOut led(D5); |
gyth | 0:65e58765adf7 | 7 | DigitalIn button_up(A2); |
gyth | 0:65e58765adf7 | 8 | DigitalIn button_center(D4); |
gyth | 0:65e58765adf7 | 9 | DigitalIn button_down(A3); |
BrentLei | 2:eac7cbeb9da0 | 10 | |
BrentLei | 2:eac7cbeb9da0 | 11 | // 初始化液晶屏 |
BrentLei | 1:08431d9e3d95 | 12 | C12832 lcd(D11, D13, D12, D7, D10); |
gyth | 0:65e58765adf7 | 13 | |
gyth | 0:65e58765adf7 | 14 | double brightness = 1.0; |
gyth | 0:65e58765adf7 | 15 | double brightness_inc = 0.1; |
gyth | 0:65e58765adf7 | 16 | |
gyth | 0:65e58765adf7 | 17 | int main() |
gyth | 0:65e58765adf7 | 18 | { |
gyth | 0:65e58765adf7 | 19 | int bt_flag = 0; |
BrentLei | 2:eac7cbeb9da0 | 20 | |
BrentLei | 2:eac7cbeb9da0 | 21 | // 液晶屏清屏 |
BrentLei | 1:08431d9e3d95 | 22 | lcd.cls(); |
BrentLei | 2:eac7cbeb9da0 | 23 | lcd.locate(0, 0); |
BrentLei | 2:eac7cbeb9da0 | 24 | lcd.printf("Hello LCD!"); |
BrentLei | 2:eac7cbeb9da0 | 25 | |
gyth | 0:65e58765adf7 | 26 | led.write(brightness); |
gyth | 0:65e58765adf7 | 27 | |
gyth | 0:65e58765adf7 | 28 | while (1) { |
gyth | 0:65e58765adf7 | 29 | bt_flag = 1; |
gyth | 0:65e58765adf7 | 30 | if(button_up==1) |
gyth | 0:65e58765adf7 | 31 | brightness -= brightness_inc; |
gyth | 0:65e58765adf7 | 32 | else if(button_down==1) |
gyth | 0:65e58765adf7 | 33 | brightness += brightness_inc; |
gyth | 0:65e58765adf7 | 34 | else if(button_center==1) |
gyth | 0:65e58765adf7 | 35 | brightness = (brightness>0.5)?1.0:0.0; |
gyth | 0:65e58765adf7 | 36 | else |
gyth | 0:65e58765adf7 | 37 | bt_flag = 0; |
gyth | 0:65e58765adf7 | 38 | if(bt_flag==1) |
gyth | 0:65e58765adf7 | 39 | { |
gyth | 0:65e58765adf7 | 40 | brightness = (brightness>1.0)?0.0:brightness; |
gyth | 0:65e58765adf7 | 41 | brightness = (brightness<0.0)?1.0:brightness; |
gyth | 0:65e58765adf7 | 42 | led.write(brightness); |
BrentLei | 2:eac7cbeb9da0 | 43 | |
BrentLei | 2:eac7cbeb9da0 | 44 | // 在液晶屏上显示LED的亮度值 |
BrentLei | 1:08431d9e3d95 | 45 | lcd.locate(0,0); |
BrentLei | 1:08431d9e3d95 | 46 | lcd.printf("Brightness = %.1f\r\n", 1.0-brightness); |
gyth | 0:65e58765adf7 | 47 | } |
gyth | 0:65e58765adf7 | 48 | wait(0.2); // 200 ms |
gyth | 0:65e58765adf7 | 49 | } |
gyth | 0:65e58765adf7 | 50 | } |