![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Lab 3 Part 4
Dependencies: mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem
Diff: main.cpp
- Revision:
- 12:94b16c66c09a
- Parent:
- 11:0309bef74ba8
- Child:
- 13:8987c75dfe41
--- a/main.cpp Wed Feb 15 14:04:02 2017 -0600 +++ b/main.cpp Thu Feb 25 18:30:28 2021 +0000 @@ -1,22 +1,138 @@ #include "mbed.h" #include "rtos.h" - -DigitalOut led1(LED1); -DigitalOut led2(LED2); -Thread thread; - -void led2_thread() { - while (true) { - led2 = !led2; - Thread::wait(1000); +#include "Speaker.h" +#include "uLCD_4DGL.h" +#include "SDFileSystem.h" +#include "wave_player.h" + +int setting = 1; + +BusOut myled(LED1,LED2,LED3,LED4); + +Serial blue(p13,p14); + +AnalogOut DACout(p18); + +wave_player waver(&DACout); + +SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card + +Mutex stdio_mutex; + +uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; + +PwmOut rLED(p21); // Light up Red LED with p21 +PwmOut gLED(p22); // Light up Green LED with p22 +PwmOut bLED(p23); // Light up Blue LED with p23 + +Thread thread1; +Thread thread2; +Thread thread3; +Thread thread4; + +/* Function Calls */ +void top_red_box() +{ + stdio_mutex.lock(); + uLCD.filled_rectangle(0, 0, 127, 63, RED); + stdio_mutex.unlock(); +} +void bot_blue_box() +{ + stdio_mutex.lock(); + uLCD.filled_rectangle(0, 63, 127, 127, BLUE); + stdio_mutex.unlock(); +} +void top_black_box() +{ + stdio_mutex.lock(); + uLCD.filled_rectangle(0, 0, 127, 63, BLACK); + stdio_mutex.unlock(); + +} +void bot_black_box() +{ + stdio_mutex.lock(); + uLCD.filled_rectangle(0, 63, 127, 127, BLACK); + stdio_mutex.unlock(); +} + + +/* Threads */ +void led_thread() +{ + while(1) { + bLED = 0; + rLED = 1; + Thread::wait(750); + rLED = 0; + bLED = 1; + Thread::wait(750); } } - -int main() { - thread.start(led2_thread); + +void speaker_thread() +{ + while(1) { + FILE *wave_file; + printf("\n\n\nHello, wave world!\n"); + wave_file=fopen("/sd/WEEWOO.wav","r"); + waver.play(wave_file); + fclose(wave_file); + } +} + +void lcd1_thread() +{ + while(1) { + top_red_box(); + Thread::wait(750); + top_black_box(); + Thread::wait(750); + } +} + +void lcd2_thread() +{ + while(1) { + bot_black_box(); + Thread::wait(750); + bot_blue_box(); + Thread::wait(750); + } +} + +int main() +{ + rLED = 0; + gLED = 0; + bLED = 0; + char bnum=0; + while(1) { + if (blue.readable() && blue.getc()=='!') { + if (blue.getc()=='B') { //button data + bnum = blue.getc(); //button number + if (bnum=='1') //is a number button 1..4 + setting = 1; + break; //turn on/off that num LED + } + } + } + + thread1.start(led_thread); + thread2.start(speaker_thread); + thread3.start(lcd1_thread); + thread4.start(lcd2_thread); while (true) { - led1 = !led1; - Thread::wait(500); + Thread::wait(500) + if (blue.readable() && blue.getc()=='!') { + if (blue.getc()=='B') { //button data + bnum = blue.getc(); //button number + if (bnum=='1') //is a number button 1..4 + setting = 1; + break; //turn on/off that num LED + } + } } }