![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Final project
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem 4180_Lab3_rtos_basic
Diff: main.cpp
- Revision:
- 8:8eb653dc6571
- Parent:
- 7:49bfd42cbf6f
- Child:
- 9:1b37fd4bf5ea
diff -r 49bfd42cbf6f -r 8eb653dc6571 main.cpp --- a/main.cpp Thu Oct 01 19:02:10 2015 +0000 +++ b/main.cpp Thu Oct 01 20:35:16 2015 +0000 @@ -1,44 +1,86 @@ #include "mbed.h" #include "rtos.h" +#include "uLCD_4DGL.h" +#include "SDFileSystem.h" +#include "wave_player.h" -PwmOut Speaker(p26); - +uLCD_4DGL myLCD(p9, p10, p11); +Mutex lcd_mutex; + PwmOut RGBLED_r(p23); PwmOut RGBLED_g(p22); PwmOut RGBLED_b(p21); +SDFileSystem sd(p5, p6, p7, p8, "sd"); + +AnalogOut Speaker(p18); +wave_player waver(&Speaker); +bool PLAY = true; +bool *PlayStopPtr = &PLAY; + +int j = 0; +int k = 0; + void ulcd1_thread(void const *args) { - while (true) { - - } + while(true) { + lcd_mutex.lock(); + myLCD.locate(0,0); + myLCD.printf("Thread1 status count: %d", j); + lcd_mutex.unlock(); + j++; + Thread::wait(150); + } } void ulcd2_thread(void const *args) { - while (true) { - - } + while(true) { + lcd_mutex.lock(); + myLCD.locate(0,5); + myLCD.printf("Thread 2 status count : %d", k); + lcd_mutex.unlock(); + k++; + Thread::wait(300); + } } void led_thread(void const *args) { - while (true) { + while(true) { + RGBLED_g = 0.0; RGBLED_r = 1.0; - Thread::wait(1000); + RGBLED_b = 0.0; + Thread::wait(300); + RGBLED_r = 0.0; + RGBLED_b = 1.0; + Thread::wait(300); } } void Speaker_thread(void const *args) { - while (true) { - - } + while(true) { + FILE *wave_file; + wave_file=fopen("/sd/mySound/Siren.wav","r"); + waver.play(wave_file,PlayStopPtr); + fclose(wave_file); + Thread::wait(1000); // wait 1.0s + } } int main() { - Thread thread(ulcd1_thread); - Thread thraed(ulcd2_thread); - Thread thread(led_thread); - Thread thread(Speaker_thread); + + myLCD.cls(); + + Thread thread0(ulcd1_thread); + Thread thread1(ulcd2_thread); + Thread thread2(led_thread); + Thread thread3(Speaker_thread); + Timer t; + t.start(); while (true) { + lcd_mutex.lock(); + myLCD.locate(0,9); + myLCD.printf("The time taken was %0.2f seconds\n", t.read()); + lcd_mutex.unlock(); Thread::wait(500); } }