jiioilh
Dependencies: 4DGL-uLCD-SE RGBLED SDFileSystem mbed-rtos mbed wave_player
Fork of rtos_mutex by
Diff: main.cpp
- Revision:
- 8:a00c598bac22
- Parent:
- 7:bd0aa7f21f53
--- a/main.cpp Wed Feb 15 13:58:42 2017 -0600 +++ b/main.cpp Thu Feb 23 22:39:45 2017 +0000 @@ -1,27 +1,105 @@ #include "mbed.h" #include "rtos.h" +#include "SDFileSystem.h" +#include "uLCD_4DGL.h" +#include "rgb-led.h" +#include "wave_player.h" +#include <string> +using namespace std; Mutex stdio_mutex; +uLCD_4DGL uLCD(p28, p27, p29); +SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card +AnalogOut DACout(p18); +wave_player waver(&DACout); +RGBLed myRGBled(p21, p22, p23); +Serial pc(USBTX, USBRX); + Thread t2; + Thread t3; + Thread t4; +string color; -void notify(const char* name, int state) { - stdio_mutex.lock(); - printf("%s: %d\n\r", name, state); - stdio_mutex.unlock(); -} -void test_thread(void const *args) { - while (true) { - notify((const char*)args, 0); Thread::wait(1000); - notify((const char*)args, 1); Thread::wait(1000); +void lightsULCD() { + while(1) { + stdio_mutex.lock(); + uLCD.locate(3,4); + uLCD.puts("Color of Led: "); + if (color == "red") { + uLCD.puts("Color of LED: red"); + } + if (color == "blue") { + uLCD.puts("Color of LED: blue"); + } + if (color == "green") { + uLCD.puts("Color of LED: green"); + } + + stdio_mutex.unlock(); + pc.printf("Hello from thread1\n"); + Thread::wait(1000); } } -int main() { - Thread t2; - Thread t3; +void timeULCD() { + int count = 0; + while(1) { + stdio_mutex.lock(); + if(count%3==0){ + uLCD.locate(3,8); + uLCD.puts("Ah, ha, ha, ha"); + } + else if(count%3==1){ + uLCD.locate(3,8); + uLCD.puts("Stayin' Alive"); + } + else { + uLCD.locate(3,8); + uLCD.puts("Stayin' Alive"); + } + count++; + stdio_mutex.unlock(); + pc.printf("Hello from thread2\n"); + + Thread::wait(1000); + } + +} - t2.start(callback(test_thread, (void *)"Th 2")); - t3.start(callback(test_thread, (void *)"Th 3")); +void playSound() { + while(1) { + FILE *wave_file; + printf("\n\n\nHello, wave world!\n"); + wave_file=fopen("/sd/stayin.wav","r"); + waver.play(wave_file); + fclose(wave_file); + pc.printf("Hello from thread3\n"); + + Thread::wait(1000); + } +} + + +int main() { + - test_thread((void *)"Th 1"); + t2.start(lightsULCD); + t3.start(timeULCD); + t4.start(playSound); + pc.printf("hello\n"); + //test_thread((void *)"Th 1"); + while(1) { + pc.printf("Hello from thread4\n"); + + myRGBled.write(1.0,0.0,0.0); //red + color = "red"; + wait(2.0); + myRGBled.write(0.0,1.0,0.0); //green + color = "green"; + wait(2.0); + myRGBled.write(0.0,0.0,1.0); //blue + color = "blue"; + wait(2.0); + Thread::wait(1000); + } }