![](/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:
- 9:1b37fd4bf5ea
- Parent:
- 8:8eb653dc6571
- Child:
- 10:a644e4e16cf4
- Child:
- 11:275cc4d62276
diff -r 8eb653dc6571 -r 1b37fd4bf5ea main.cpp --- a/main.cpp Thu Oct 01 20:35:16 2015 +0000 +++ b/main.cpp Mon Mar 01 22:25:07 2021 +0000 @@ -3,13 +3,18 @@ #include "uLCD_4DGL.h" #include "SDFileSystem.h" #include "wave_player.h" +#include "PlatformMutex.h" -uLCD_4DGL myLCD(p9, p10, p11); -Mutex lcd_mutex; + -PwmOut RGBLED_r(p23); -PwmOut RGBLED_g(p22); -PwmOut RGBLED_b(p21); +uLCD_4DGL myLCD(p28, p27, p30); +Mutex lcd_mutex; +RawSerial pc(USBTX, USBRX); +Serial bluemod(p13,p14); + +PwmOut red(p23); +PwmOut green(p22); +PwmOut blue(p21); SDFileSystem sd(p5, p6, p7, p8, "sd"); @@ -18,47 +23,41 @@ bool PLAY = true; bool *PlayStopPtr = &PLAY; -int j = 0; -int k = 0; - -void ulcd1_thread(void const *args) { - while(true) { +// Thread 1 +// print counter into first line and wait for 1 s +void thread1(void const *args) +{ + int i; + while(true) { // thread loop lcd_mutex.lock(); myLCD.locate(0,0); - myLCD.printf("Thread1 status count: %d", j); + myLCD.printf("Weeeee Woooo"); lcd_mutex.unlock(); - j++; - Thread::wait(150); + i++; + Thread::wait(1000); } } -void ulcd2_thread(void const *args) { - while(true) { +// Thread 2 +// print counter into third line and wait for 0,5s +void thread2(void const *args) +{ + int k; + while(true) { // thread loop lcd_mutex.lock(); - myLCD.locate(0,5); - myLCD.printf("Thread 2 status count : %d", k); + myLCD.locate(0,20); + myLCD.printf("Pull Over."); lcd_mutex.unlock(); k++; - Thread::wait(300); + Thread::wait(500); // wait 0.5s } } -void led_thread(void const *args) { - while(true) { - RGBLED_g = 0.0; - RGBLED_r = 1.0; - RGBLED_b = 0.0; - Thread::wait(300); - RGBLED_r = 0.0; - RGBLED_b = 1.0; - Thread::wait(300); - } -} -void Speaker_thread(void const *args) { +void thread4(void const *args) { while(true) { FILE *wave_file; - wave_file=fopen("/sd/mySound/Siren.wav","r"); + wave_file=fopen("/sd/Siren.wav","r"); waver.play(wave_file,PlayStopPtr); fclose(wave_file); Thread::wait(1000); // wait 1.0s @@ -69,10 +68,10 @@ myLCD.cls(); - Thread thread0(ulcd1_thread); - Thread thread1(ulcd2_thread); - Thread thread2(led_thread); - Thread thread3(Speaker_thread); + Thread t1(thread1); + Thread t2(thread2); + // Thread t3(thread3); + Thread t4(thread4); Timer t; t.start(); @@ -80,6 +79,26 @@ lcd_mutex.lock(); myLCD.locate(0,9); myLCD.printf("The time taken was %0.2f seconds\n", t.read()); + char bred=0; + char bgreen=0; + char bblue=0; + red = green = blue = 0; + while(1) { + if (bluemod.getc()=='!') { + if (bluemod.getc()=='C') { //color data packet + bred = bluemod.getc(); // RGB color values + bgreen = bluemod.getc(); + bblue = bluemod.getc(); + if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) { //checksum OK? + red = bred/255.0; //send new color to RGB LED PWM outputs + green = bgreen/255.0; + blue = bblue/255.0; + } + } + } + } + + lcd_mutex.unlock(); Thread::wait(500); }