AUP_Lab7_RTOS

Dependencies:   C12832 MMA7660 mbed-rtos mbed

Fork of AUP_Lab6_Music by Lei Lei

Committer:
BrentLei
Date:
Wed Jul 08 00:05:05 2015 +0000
Revision:
2:09ee85ab1717
Parent:
1:08431d9e3d95
Child:
3:640558c1c0d3
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gyth 0:65e58765adf7 1 #include "mbed.h"
BrentLei 1:08431d9e3d95 2 #include "C12832.h"
gyth 0:65e58765adf7 3
BrentLei 2:09ee85ab1717 4 // 添加MMA7660库文件
BrentLei 2:09ee85ab1717 5 #include "MMA7660.h"
BrentLei 2:09ee85ab1717 6
gyth 0:65e58765adf7 7 PwmOut led(D5);
gyth 0:65e58765adf7 8 DigitalIn button_up(A2);
gyth 0:65e58765adf7 9 DigitalIn button_center(D4);
gyth 0:65e58765adf7 10 DigitalIn button_down(A3);
BrentLei 1:08431d9e3d95 11 C12832 lcd(D11, D13, D12, D7, D10);
gyth 0:65e58765adf7 12
BrentLei 2:09ee85ab1717 13 // 初始化MMA7660
BrentLei 2:09ee85ab1717 14 MMA7660 MMA(D14, D15);
BrentLei 2:09ee85ab1717 15
gyth 0:65e58765adf7 16 double brightness = 1.0;
gyth 0:65e58765adf7 17 double brightness_inc = 0.1;
gyth 0:65e58765adf7 18
gyth 0:65e58765adf7 19 int main()
gyth 0:65e58765adf7 20 {
gyth 0:65e58765adf7 21 int bt_flag = 0;
BrentLei 1:08431d9e3d95 22 lcd.cls();
gyth 0:65e58765adf7 23 led.write(brightness);
gyth 0:65e58765adf7 24
gyth 0:65e58765adf7 25 while (1) {
gyth 0:65e58765adf7 26 bt_flag = 1;
gyth 0:65e58765adf7 27 if(button_up==1)
gyth 0:65e58765adf7 28 brightness -= brightness_inc;
gyth 0:65e58765adf7 29 else if(button_down==1)
gyth 0:65e58765adf7 30 brightness += brightness_inc;
gyth 0:65e58765adf7 31 else if(button_center==1)
gyth 0:65e58765adf7 32 brightness = (brightness>0.5)?1.0:0.0;
gyth 0:65e58765adf7 33 else
gyth 0:65e58765adf7 34 bt_flag = 0;
gyth 0:65e58765adf7 35 if(bt_flag==1)
gyth 0:65e58765adf7 36 {
gyth 0:65e58765adf7 37 brightness = (brightness>1.0)?0.0:brightness;
gyth 0:65e58765adf7 38 brightness = (brightness<0.0)?1.0:brightness;
gyth 0:65e58765adf7 39 led.write(brightness);
gyth 0:65e58765adf7 40 }
BrentLei 2:09ee85ab1717 41 lcd.locate(0, 0);
BrentLei 2:09ee85ab1717 42 lcd.printf("Brightness = %.1f\r\n", 1.0 - brightness);
BrentLei 2:09ee85ab1717 43
BrentLei 2:09ee85ab1717 44 // 显示加速度计的测量结果
BrentLei 2:09ee85ab1717 45 lcd.printf("x=%.2f y=%.2f z=%.2f", MMA.x(), MMA.y(), MMA.z());
BrentLei 2:09ee85ab1717 46 wait(0.2);
gyth 0:65e58765adf7 47 }
gyth 0:65e58765adf7 48 }