change in mbed rtos library

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

Fork of rtos_basic by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "uLCD_4DGL.h"
00004 #include "RGB_LED.h"
00005 #include "SDFileSystem.h"
00006 #include "wave_player.h"
00007 
00008 
00009 DigitalOut led1(LED1);
00010 DigitalOut led2(LED2);
00011 Thread thread;
00012 Thread thread2;
00013 Thread thread3;
00014 Thread thread4;
00015 Mutex stdio_mutex;
00016 AnalogOut DACout(p18); 
00017 SDFileSystem sd(p5, p6, p7, p8, "sd");
00018 Serial bluemod(p9,p10);
00019 wave_player waver(&DACout);
00020 uLCD_4DGL uLCD(p28,p27,p29);
00021 RGBLed myRGBled(p22,p23,p24);
00022 char bred=0;
00023 char bgreen=0;
00024 char bblue=0;
00025 int bnum = 0;
00026 int red=0;
00027 int green=0;
00028 int blue = 0;
00029 void printName() {
00030   stdio_mutex.lock();
00031   uLCD.text_string("LETS DANCE!",1,14, FONT_7X8, RED);
00032   Thread::wait(1000);
00033   uLCD.text_string("LETS DANCE!",1,14, FONT_7X8, BLACK);
00034   uLCD.text_string("TURN UP!",1,14,FONT_7X8, BLUE); 
00035   stdio_mutex.unlock();
00036  }
00037 void colorULCD() {
00038   stdio_mutex.lock();
00039   uLCD.line(60,80,60,0,128*65536+128*256+128);
00040   uLCD.filled_circle(60,60,20,RED);
00041   Thread::wait(500);
00042   uLCD.line(60,80,60,0,128*65536+128*256+128);
00043   uLCD.filled_circle(60,60,20,BLUE);
00044   Thread::wait(500);
00045   uLCD.line(60,80,60,0,128*65536+128*256+128);
00046   uLCD.filled_circle(60,60,20,RED);
00047   Thread::wait(500);
00048   uLCD.line(60,80,60,0,128*65536+128*256+128);
00049   uLCD.filled_circle(60,60,20, 255*65536+165*256+0);
00050   Thread::wait(500);
00051   uLCD.line(60,80,60,0,128*65536+128*256+128);
00052   uLCD.filled_circle(60,60,20,255*65536+255*256+0);
00053   Thread::wait(500);
00054   uLCD.line(60,80,60,0,128*65536+128*256+128);
00055   uLCD.filled_circle(60,60,20,GREEN);
00056   Thread::wait(500);
00057   uLCD.line(60,80,60,0,128*65536+128*256+128);
00058   uLCD.filled_circle(60,60,20,BLUE);
00059   Thread::wait(500);
00060   uLCD.line(60,80,60,0,128*65536+128*256+128);
00061   uLCD.filled_circle(60,60,20,75*65536+0*256+130);
00062   Thread::wait(500);
00063   uLCD.line(60,80,60,0,128*65536+128*256+128);
00064   uLCD.filled_circle(60,60,20,128*65536+0*256+128);
00065   stdio_mutex.unlock();
00066  }
00067  
00068  void RGB_LED() {
00069   
00070    if (bluemod.getc()=='!') {
00071             if (bluemod.getc()=='C') { //color data packet
00072                 stdio_mutex.lock();
00073                 bred = bluemod.getc(); // RGB color values
00074                 bgreen = bluemod.getc();
00075                 bblue = bluemod.getc();
00076                 if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) {
00077                      //checksum OK?
00078                     stdio_mutex.unlock();
00079                     red = bred/255.0; //send new color to RGB LED PWM outputs
00080                     green = bgreen/255.0;
00081                     blue = bblue/255.0;
00082                     myRGBled.write(red,green,blue);
00083                 }
00084             }
00085         } 
00086     }
00087   void Speaker_Function() {
00088      FILE *wave_file;
00089      
00090      if (bluemod.getc()=='!') {
00091             if (bluemod.getc()=='B') { //button data
00092                 stdio_mutex.lock();
00093                 bnum = bluemod.getc();
00094                 stdio_mutex.unlock();
00095                 if (bnum=='1') { //is a number button 1..4
00096                      wave_file=fopen("/sd/wavfiles/trapman.wav","r");
00097                      waver.play(wave_file);
00098                       fclose(wave_file);  //turn on/off that num LED
00099             }
00100         }
00101      }
00102   }
00103   //myRGBled.write(1.0f, 0, 0); // turn the RGB LED red 
00104   //Thread::wait(500); // wait for 1 second 
00105   //myRGBled.write(0, 0, 255); // turn the RGB LED blue 
00106   //Thread::wait(500); // wait for 1 second 
00107   // Example blended myRGBled.writes: 
00108   //myRGBled.write(255,0,0); // turn the RGB LED red 
00109   //Thread::wait(500); // wait for 1 second 
00110   //myRGBled.write(237,109,0); // turn the RGB LED orange 
00111   //Thread::wait(500); // wait for 1 second 
00112   //myRGBled.write(255,215,0); // turn the RGB LED yellow 
00113   //Thread::wait(500); // wait for 1 second 
00114   //myRGBled.write(34,139,34); // turn the RGB LED green 
00115   //Thread::wait(500); // wait for 1 second 
00116   //myRGBled.write(0,0,255); // turn the RGB LED blue 
00117   //Thread::wait(050); // wait for 1 second
00118   //myRGBled.write(0,46,90); // turn the RGB LED indigo 
00119   //Thread::wait(500); // wait for 1 second
00120   //myRGBled.write(128,0,128); // turn the RGB LED purple 
00121 void uLCD_thread1() {
00122     while (true) {
00123     colorULCD();
00124     Thread::wait(500);
00125     }
00126         
00127 }
00128 void uLCD_thread2() {
00129     while (true) {
00130     printName();
00131     Thread::wait(250);    
00132     }
00133     
00134  }
00135 void RGB_thread3(){
00136     while (true){
00137     RGB_LED();
00138     Thread::wait(100);
00139     }
00140   }
00141 void Speaker_Thread(){
00142     while(true){
00143     Speaker_Function();
00144     Thread::wait(250);
00145     }
00146 }
00147 int main() {
00148    // thread.start(uLCD_thread1);
00149    thread2.start(uLCD_thread2);
00150    thread3.start(RGB_thread3);
00151    thread4.start(Speaker_Thread);
00152   //  FILE *wave_file;
00153    // wave_file=fopen("/sd/wavfiles/trapman.wav","r");
00154    // waver.play(wave_file);
00155    // fclose(wave_file);    
00156 }
00157  
00158 
00159