change in mbed rtos library

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

Fork of rtos_basic by mbed official

Revision:
13:b0bfe7f4472a
Parent:
12:fb46c68fa360
--- a/main.cpp	Wed Feb 28 07:20:20 2018 +0000
+++ b/main.cpp	Wed Feb 28 09:54:23 2018 +0000
@@ -2,6 +2,8 @@
 #include "rtos.h"
 #include "uLCD_4DGL.h"
 #include "RGB_LED.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
 
 
 DigitalOut led1(LED1);
@@ -11,13 +13,25 @@
 Thread thread3;
 Thread thread4;
 Mutex stdio_mutex;
+AnalogOut DACout(p18); 
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+Serial bluemod(p9,p10);
+wave_player waver(&DACout);
 uLCD_4DGL uLCD(p28,p27,p29);
 RGBLed myRGBled(p22,p23,p24);
+char bred=0;
+char bgreen=0;
+char bblue=0;
+int bnum = 0;
+int red=0;
+int green=0;
+int blue = 0;
 void printName() {
   stdio_mutex.lock();
-  uLCD.printf("\nMy name is Barry Johnson-Smith\n");
-  //Time to dance at same time as color changing.
-  uLCD.cls();
+  uLCD.text_string("LETS DANCE!",1,14, FONT_7X8, RED);
+  Thread::wait(1000);
+  uLCD.text_string("LETS DANCE!",1,14, FONT_7X8, BLACK);
+  uLCD.text_string("TURN UP!",1,14,FONT_7X8, BLUE); 
   stdio_mutex.unlock();
  }
 void colorULCD() {
@@ -51,6 +65,59 @@
   stdio_mutex.unlock();
  }
  
+ void RGB_LED() {
+  
+   if (bluemod.getc()=='!') {
+            if (bluemod.getc()=='C') { //color data packet
+                stdio_mutex.lock();
+                bred = bluemod.getc(); // RGB color values
+                bgreen = bluemod.getc();
+                bblue = bluemod.getc();
+                if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) {
+                     //checksum OK?
+                    stdio_mutex.unlock();
+                    red = bred/255.0; //send new color to RGB LED PWM outputs
+                    green = bgreen/255.0;
+                    blue = bblue/255.0;
+                    myRGBled.write(red,green,blue);
+                }
+            }
+        } 
+    }
+  void Speaker_Function() {
+     FILE *wave_file;
+     
+     if (bluemod.getc()=='!') {
+            if (bluemod.getc()=='B') { //button data
+                stdio_mutex.lock();
+                bnum = bluemod.getc();
+                stdio_mutex.unlock();
+                if (bnum=='1') { //is a number button 1..4
+                     wave_file=fopen("/sd/wavfiles/trapman.wav","r");
+                     waver.play(wave_file);
+                      fclose(wave_file);  //turn on/off that num LED
+            }
+        }
+     }
+  }
+  //myRGBled.write(1.0f, 0, 0); // turn the RGB LED red 
+  //Thread::wait(500); // wait for 1 second 
+  //myRGBled.write(0, 0, 255); // turn the RGB LED blue 
+  //Thread::wait(500); // wait for 1 second 
+  // Example blended myRGBled.writes: 
+  //myRGBled.write(255,0,0); // turn the RGB LED red 
+  //Thread::wait(500); // wait for 1 second 
+  //myRGBled.write(237,109,0); // turn the RGB LED orange 
+  //Thread::wait(500); // wait for 1 second 
+  //myRGBled.write(255,215,0); // turn the RGB LED yellow 
+  //Thread::wait(500); // wait for 1 second 
+  //myRGBled.write(34,139,34); // turn the RGB LED green 
+  //Thread::wait(500); // wait for 1 second 
+  //myRGBled.write(0,0,255); // turn the RGB LED blue 
+  //Thread::wait(050); // wait for 1 second
+  //myRGBled.write(0,46,90); // turn the RGB LED indigo 
+  //Thread::wait(500); // wait for 1 second
+  //myRGBled.write(128,0,128); // turn the RGB LED purple 
 void uLCD_thread1() {
     while (true) {
     colorULCD();
@@ -61,35 +128,32 @@
 void uLCD_thread2() {
     while (true) {
     printName();
-    Thread::wait(1000);    
+    Thread::wait(250);    
     }
     
  }
-void RGB_LED() {
-  while(true) {
-  myRGBled.write(1.0f, 0, 0); // turn the RGB LED red 
-  Thread::wait(500); // wait for 1 second 
-  myRGBled.write(0, 0, 255); // turn the RGB LED blue 
-  Thread::wait(500); // wait for 1 second 
-  // Example blended myRGBled.writes: 
-  myRGBled.write(255,0,0); // turn the RGB LED red 
-  Thread::wait(500); // wait for 1 second 
-  myRGBled.write(237,109,0); // turn the RGB LED orange 
-  Thread::wait(500); // wait for 1 second 
-  myRGBled.write(255,215,0); // turn the RGB LED yellow 
-  Thread::wait(500); // wait for 1 second 
-  myRGBled.write(34,139,34); // turn the RGB LED green 
-  Thread::wait(500); // wait for 1 second 
-  myRGBled.write(0,0,255); // turn the RGB LED blue 
-  Thread::wait(050); // wait for 1 second
-  myRGBled.write(0,46,90); // turn the RGB LED indigo 
-  Thread::wait(500); // wait for 1 second
-  myRGBled.write(128,0,128); // turn the RGB LED purple 
-  Thread::wait(500); // wait for 1 second
+void RGB_thread3(){
+    while (true){
+    RGB_LED();
+    Thread::wait(100);
+    }
   }
-} 
+void Speaker_Thread(){
+    while(true){
+    Speaker_Function();
+    Thread::wait(250);
+    }
+}
 int main() {
-   thread.start(uLCD_thread1);
-    //thread2.start(uLCD_thread2);
-    thread3.start(RGB_LED);  
+   // thread.start(uLCD_thread1);
+   thread2.start(uLCD_thread2);
+   thread3.start(RGB_thread3);
+   thread4.start(Speaker_Thread);
+  //  FILE *wave_file;
+   // wave_file=fopen("/sd/wavfiles/trapman.wav","r");
+   // waver.play(wave_file);
+   // fclose(wave_file);    
 }
+ 
+
+