jiioilh

Dependencies:   4DGL-uLCD-SE RGBLED SDFileSystem mbed-rtos mbed wave_player

Fork of rtos_mutex by mbed official

Committer:
elirobelo
Date:
Thu Feb 23 22:40:42 2017 +0000
Revision:
9:d91dfc53b6ec
Parent:
8:a00c598bac22
lab 3 part 2a;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:0f886ffbe0c1 1 #include "mbed.h"
mbed_official 7:bd0aa7f21f53 2 #include "rtos.h"
elirobelo 8:a00c598bac22 3 #include "SDFileSystem.h"
elirobelo 8:a00c598bac22 4 #include "uLCD_4DGL.h"
elirobelo 8:a00c598bac22 5 #include "rgb-led.h"
elirobelo 8:a00c598bac22 6 #include "wave_player.h"
elirobelo 8:a00c598bac22 7 #include <string>
elirobelo 8:a00c598bac22 8 using namespace std;
emilmont 1:0f886ffbe0c1 9
Bartek Szatkowski 5:384d6cef11d4 10 Mutex stdio_mutex;
elirobelo 8:a00c598bac22 11 uLCD_4DGL uLCD(p28, p27, p29);
elirobelo 8:a00c598bac22 12 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
elirobelo 8:a00c598bac22 13 AnalogOut DACout(p18);
elirobelo 8:a00c598bac22 14 wave_player waver(&DACout);
elirobelo 8:a00c598bac22 15 RGBLed myRGBled(p21, p22, p23);
elirobelo 8:a00c598bac22 16 Serial pc(USBTX, USBRX);
elirobelo 8:a00c598bac22 17 Thread t2;
elirobelo 8:a00c598bac22 18 Thread t3;
elirobelo 8:a00c598bac22 19 Thread t4;
elirobelo 8:a00c598bac22 20 string color;
mbed_official 7:bd0aa7f21f53 21
emilmont 1:0f886ffbe0c1 22
elirobelo 8:a00c598bac22 23 void lightsULCD() {
elirobelo 8:a00c598bac22 24 while(1) {
elirobelo 8:a00c598bac22 25 stdio_mutex.lock();
elirobelo 8:a00c598bac22 26 uLCD.locate(3,4);
elirobelo 8:a00c598bac22 27 uLCD.puts("Color of Led: ");
elirobelo 8:a00c598bac22 28 if (color == "red") {
elirobelo 8:a00c598bac22 29 uLCD.puts("Color of LED: red");
elirobelo 8:a00c598bac22 30 }
elirobelo 8:a00c598bac22 31 if (color == "blue") {
elirobelo 8:a00c598bac22 32 uLCD.puts("Color of LED: blue");
elirobelo 8:a00c598bac22 33 }
elirobelo 8:a00c598bac22 34 if (color == "green") {
elirobelo 8:a00c598bac22 35 uLCD.puts("Color of LED: green");
elirobelo 8:a00c598bac22 36 }
elirobelo 8:a00c598bac22 37
elirobelo 8:a00c598bac22 38 stdio_mutex.unlock();
elirobelo 8:a00c598bac22 39 pc.printf("Hello from thread1\n");
elirobelo 8:a00c598bac22 40 Thread::wait(1000);
emilmont 1:0f886ffbe0c1 41 }
emilmont 1:0f886ffbe0c1 42 }
emilmont 1:0f886ffbe0c1 43
elirobelo 8:a00c598bac22 44 void timeULCD() {
elirobelo 8:a00c598bac22 45 int count = 0;
elirobelo 8:a00c598bac22 46 while(1) {
elirobelo 8:a00c598bac22 47 stdio_mutex.lock();
elirobelo 8:a00c598bac22 48 if(count%3==0){
elirobelo 8:a00c598bac22 49 uLCD.locate(3,8);
elirobelo 8:a00c598bac22 50 uLCD.puts("Ah, ha, ha, ha");
elirobelo 8:a00c598bac22 51 }
elirobelo 8:a00c598bac22 52 else if(count%3==1){
elirobelo 8:a00c598bac22 53 uLCD.locate(3,8);
elirobelo 8:a00c598bac22 54 uLCD.puts("Stayin' Alive");
elirobelo 8:a00c598bac22 55 }
elirobelo 8:a00c598bac22 56 else {
elirobelo 8:a00c598bac22 57 uLCD.locate(3,8);
elirobelo 8:a00c598bac22 58 uLCD.puts("Stayin' Alive");
elirobelo 8:a00c598bac22 59 }
elirobelo 8:a00c598bac22 60 count++;
elirobelo 8:a00c598bac22 61 stdio_mutex.unlock();
elirobelo 8:a00c598bac22 62 pc.printf("Hello from thread2\n");
elirobelo 8:a00c598bac22 63
elirobelo 8:a00c598bac22 64 Thread::wait(1000);
elirobelo 8:a00c598bac22 65 }
elirobelo 8:a00c598bac22 66
elirobelo 8:a00c598bac22 67 }
mbed_official 7:bd0aa7f21f53 68
elirobelo 8:a00c598bac22 69 void playSound() {
elirobelo 8:a00c598bac22 70 while(1) {
elirobelo 8:a00c598bac22 71 FILE *wave_file;
elirobelo 8:a00c598bac22 72 printf("\n\n\nHello, wave world!\n");
elirobelo 8:a00c598bac22 73 wave_file=fopen("/sd/stayin.wav","r");
elirobelo 8:a00c598bac22 74 waver.play(wave_file);
elirobelo 8:a00c598bac22 75 fclose(wave_file);
elirobelo 8:a00c598bac22 76 pc.printf("Hello from thread3\n");
elirobelo 8:a00c598bac22 77
elirobelo 8:a00c598bac22 78 Thread::wait(1000);
elirobelo 8:a00c598bac22 79 }
elirobelo 8:a00c598bac22 80 }
elirobelo 8:a00c598bac22 81
elirobelo 8:a00c598bac22 82
elirobelo 8:a00c598bac22 83 int main() {
elirobelo 8:a00c598bac22 84
Bartek Szatkowski 5:384d6cef11d4 85
elirobelo 8:a00c598bac22 86 t2.start(lightsULCD);
elirobelo 8:a00c598bac22 87 t3.start(timeULCD);
elirobelo 8:a00c598bac22 88 t4.start(playSound);
elirobelo 8:a00c598bac22 89 pc.printf("hello\n");
elirobelo 8:a00c598bac22 90 //test_thread((void *)"Th 1");
elirobelo 8:a00c598bac22 91 while(1) {
elirobelo 8:a00c598bac22 92 pc.printf("Hello from thread4\n");
elirobelo 8:a00c598bac22 93
elirobelo 8:a00c598bac22 94 myRGBled.write(1.0,0.0,0.0); //red
elirobelo 8:a00c598bac22 95 color = "red";
elirobelo 8:a00c598bac22 96 wait(2.0);
elirobelo 8:a00c598bac22 97 myRGBled.write(0.0,1.0,0.0); //green
elirobelo 8:a00c598bac22 98 color = "green";
elirobelo 8:a00c598bac22 99 wait(2.0);
elirobelo 8:a00c598bac22 100 myRGBled.write(0.0,0.0,1.0); //blue
elirobelo 8:a00c598bac22 101 color = "blue";
elirobelo 8:a00c598bac22 102 wait(2.0);
elirobelo 8:a00c598bac22 103 Thread::wait(1000);
elirobelo 8:a00c598bac22 104 }
emilmont 1:0f886ffbe0c1 105 }