AUP_Lab7_RTOS

Dependencies:   C12832 MMA7660 mbed-rtos mbed

Fork of AUP_Lab6_Music by Lei Lei

Committer:
BrentLei
Date:
Wed Jul 08 05:34:29 2015 +0000
Revision:
4:dbce53c4e44d
Parent:
3:640558c1c0d3
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gyth 0:65e58765adf7 1 #include "mbed.h"
BrentLei 4:dbce53c4e44d 2 #include "rtos.h"
BrentLei 1:08431d9e3d95 3 #include "C12832.h"
BrentLei 3:640558c1c0d3 4 #include "MMA7660.h"
gyth 0:65e58765adf7 5
BrentLei 4:dbce53c4e44d 6 // Define the mutex
BrentLei 4:dbce53c4e44d 7 Mutex lcd_mutex;
BrentLei 4:dbce53c4e44d 8 Mutex acc_mutex;
BrentLei 4:dbce53c4e44d 9
BrentLei 4:dbce53c4e44d 10 PwmOut led(D9);
BrentLei 4:dbce53c4e44d 11 AnalogIn pot1(A0);
BrentLei 4:dbce53c4e44d 12 C12832 lcd(D11, D13, D12, D7, D10);
BrentLei 4:dbce53c4e44d 13 MMA7660 MMA(D14, D15);
BrentLei 3:640558c1c0d3 14
BrentLei 4:dbce53c4e44d 15 // Adjust the brightness of the LED
BrentLei 4:dbce53c4e44d 16 void adjust_brightness(void const *args){
BrentLei 4:dbce53c4e44d 17 while(1){
BrentLei 4:dbce53c4e44d 18 led = 1 - pot1.read();
BrentLei 4:dbce53c4e44d 19 Thread::wait(50);
BrentLei 4:dbce53c4e44d 20 }
BrentLei 4:dbce53c4e44d 21 }
BrentLei 4:dbce53c4e44d 22
BrentLei 4:dbce53c4e44d 23 //Display LED brightness on the LCD
BrentLei 4:dbce53c4e44d 24 void disp_led_thread(void const *args){
BrentLei 4:dbce53c4e44d 25 while(1){
BrentLei 4:dbce53c4e44d 26 lcd_mutex.lock();
BrentLei 4:dbce53c4e44d 27 lcd.locate(0, 0);
BrentLei 4:dbce53c4e44d 28 lcd.printf("Brightness: %.2f", 1 - led);
BrentLei 4:dbce53c4e44d 29 lcd_mutex.unlock();
BrentLei 4:dbce53c4e44d 30 Thread::wait(100);
BrentLei 4:dbce53c4e44d 31 }
BrentLei 4:dbce53c4e44d 32 }
BrentLei 2:09ee85ab1717 33
BrentLei 4:dbce53c4e44d 34 // Display acceleration x on the LCD
BrentLei 4:dbce53c4e44d 35 void disp_x_thread(void const *args){
BrentLei 4:dbce53c4e44d 36 while(1){
BrentLei 4:dbce53c4e44d 37 lcd_mutex.lock();
BrentLei 4:dbce53c4e44d 38 acc_mutex.lock();
BrentLei 4:dbce53c4e44d 39 lcd.locate(0, 8);
BrentLei 4:dbce53c4e44d 40 lcd.printf("x=%.2f", MMA.x());
BrentLei 4:dbce53c4e44d 41 acc_mutex.unlock();
BrentLei 4:dbce53c4e44d 42 lcd_mutex.unlock();
BrentLei 4:dbce53c4e44d 43 Thread::wait(100);
BrentLei 4:dbce53c4e44d 44 }
BrentLei 4:dbce53c4e44d 45 }
gyth 0:65e58765adf7 46
BrentLei 4:dbce53c4e44d 47 // Display acceleration y on the LCD
BrentLei 4:dbce53c4e44d 48 void disp_y_thread(void const *args){
BrentLei 4:dbce53c4e44d 49 while(1){
BrentLei 4:dbce53c4e44d 50 lcd_mutex.lock();
BrentLei 4:dbce53c4e44d 51 acc_mutex.lock();
BrentLei 4:dbce53c4e44d 52 lcd.locate(40, 8);
BrentLei 4:dbce53c4e44d 53 lcd.printf("y=%.2f", MMA.y());
BrentLei 4:dbce53c4e44d 54 acc_mutex.unlock();
BrentLei 4:dbce53c4e44d 55 lcd_mutex.unlock();
BrentLei 4:dbce53c4e44d 56 Thread::wait(100);
BrentLei 4:dbce53c4e44d 57 }
BrentLei 4:dbce53c4e44d 58 }
BrentLei 2:09ee85ab1717 59
BrentLei 4:dbce53c4e44d 60 // Display acceleration z on the LCD
BrentLei 4:dbce53c4e44d 61 void disp_z_thread(void const *args){
BrentLei 4:dbce53c4e44d 62 while(1){
BrentLei 4:dbce53c4e44d 63 lcd_mutex.lock();
BrentLei 4:dbce53c4e44d 64 acc_mutex.lock();
BrentLei 4:dbce53c4e44d 65 lcd.locate(80, 8);
BrentLei 4:dbce53c4e44d 66 lcd.printf("z=%.2f", MMA.z());
BrentLei 4:dbce53c4e44d 67 acc_mutex.unlock();
BrentLei 4:dbce53c4e44d 68 lcd_mutex.unlock();
BrentLei 4:dbce53c4e44d 69 Thread::wait(100);
BrentLei 4:dbce53c4e44d 70 }
BrentLei 4:dbce53c4e44d 71 }
gyth 0:65e58765adf7 72
gyth 0:65e58765adf7 73 int main()
gyth 0:65e58765adf7 74 {
BrentLei 1:08431d9e3d95 75 lcd.cls();
BrentLei 4:dbce53c4e44d 76
BrentLei 4:dbce53c4e44d 77 Thread thread1(adjust_brightness);
BrentLei 4:dbce53c4e44d 78 Thread thread2(disp_led_thread);
BrentLei 4:dbce53c4e44d 79 Thread thread3(disp_x_thread);
BrentLei 4:dbce53c4e44d 80 Thread thread4(disp_y_thread);
BrentLei 4:dbce53c4e44d 81 Thread thread5(disp_z_thread);
BrentLei 4:dbce53c4e44d 82
BrentLei 4:dbce53c4e44d 83 // Sleep and wait for interrupt
gyth 0:65e58765adf7 84 while (1) {
BrentLei 4:dbce53c4e44d 85 __wfi();
gyth 0:65e58765adf7 86 }
gyth 0:65e58765adf7 87 }