adfdadf

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

Fork of rtos_mutex 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 "SDFileSystem.h"
00004 #include "wave_player.h"
00005 //additional for Lab4
00006 //#include "PinDetect.h"
00007 #include "uLCD_4DGL.h"
00008 #include <vector>
00009 #include <string>
00010 #include "ShiftBrite.h"
00011 
00012 uLCD_4DGL uLCD(p28,p27,p29); // create a global LCD object
00013 //uLCD_4DGL uLCD(p28, p27, p29);
00014 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
00015 DigitalIn detectSD(p12); //connect CD 
00016 AnalogOut DACout(p18); //speaker
00017 wave_player waver(&DACout);  //wave player library
00018 //DigitalOut latch(p15);
00019 //DigitalOut enable(p16);
00020 SPI spi(p11, p12, p13);
00021 DigitalOut led1(LED1);
00022 DigitalOut led2(LED2);
00023 ShiftBrite myBrite(p15,p16,spi); //latch, enable, spi
00024 
00025 
00026 Mutex stdio_mutex; 
00027 
00028 //shiftbrite
00029 /*void RGB_LED(int red, int green, int blue) {
00030     unsigned int low_color=0;
00031     unsigned int high_color=0;
00032     high_color=(blue<<4)|((red&0x3C0)>>6);
00033     low_color=(((red&0x3F)<<10)|(green));
00034     spi.write(high_color);
00035     spi.write(low_color);
00036     latch=1;
00037     latch=0;
00038 }
00039 */
00040 void lcd1_thread(void const *args) {
00041     while(1){
00042         int drop = rand()% 140;
00043         for(int i = 0; i < 140; i += 3){
00044             stdio_mutex.lock();
00045             uLCD.filled_circle(i-3,drop,5,BLACK);
00046             uLCD.filled_circle(i,drop,5,BLUE);
00047             stdio_mutex.unlock();
00048             //Thread::wait(50);
00049         }
00050     }
00051 }
00052 
00053 void lcd2_thread(void const *args) {
00054     Thread::wait(250);
00055     while(1){
00056         int drop = rand()% 140;
00057         for(int i = 0; i < 140; i += 6){
00058             stdio_mutex.lock();
00059             uLCD.filled_circle(i-6,drop,5,BLACK);
00060             uLCD.filled_circle(i,drop,5,BLUE);
00061             stdio_mutex.unlock();
00062             //Thread::wait(200);
00063         }
00064     }
00065 }
00066 
00067 void lcd3_thread(void const *args) {
00068     Thread::wait(100);
00069     while(1){
00070         int drop = rand()% 140;
00071         for(int i = 0; i < 140; i += 2){
00072             stdio_mutex.lock();
00073             uLCD.filled_circle(i-2,drop,5,BLACK);
00074             uLCD.filled_circle(i,drop,5,BLUE);
00075             stdio_mutex.unlock();
00076             //Thread::wait(100);
00077         }
00078     }
00079 }
00080 
00081 void wav_thread(void const *args) {
00082     while(1) {
00083         FILE *wave_file;
00084         printf("\n\n\nHello, wave world!\n\r");
00085         wave_file=fopen("/sd/beethoven.wav","r");
00086         printf("hello\n\r");
00087         if (wave_file) {
00088             printf("wave file found\n\r");
00089             }
00090         else {
00091             printf("file not found\n\r");
00092             }
00093         waver.play(wave_file);
00094         fclose(wave_file);
00095         Thread::wait(1000);
00096     }
00097 }
00098 
00099 void shift_thread(void const *args){
00100     
00101     int r,g,b;
00102     while(1) {
00103         r=g=b=50;
00104         myBrite.Write(250,250,160);
00105         Thread::wait(150);
00106         myBrite.Write(0,0,0);
00107         Thread::wait(3000+(rand()%10000));
00108         myBrite.Brightness(r,g,b);
00109         if(r<1023)
00110             r+=50;
00111         else
00112             r=50;
00113         g=b=r;
00114         
00115     }
00116 
00117     
00118 }
00119 
00120 void led2_thread(void const *args) {
00121     while (true) {
00122         led2 = !led2;
00123         Thread::wait(1000);
00124     }
00125 }
00126 
00127 void notify(const char* name, int state) {
00128     stdio_mutex.lock();
00129     printf("%s: %d\n\r", name, state);
00130     stdio_mutex.unlock();
00131 }
00132 
00133 int main() {
00134     uLCD.baudrate(BAUD_3000000);
00135     Thread audio(wav_thread);
00136     Thread thread(led2_thread);
00137     Thread lighting(shift_thread);
00138     Thread image1(lcd1_thread);
00139     Thread image2(lcd2_thread);
00140     Thread image3(lcd3_thread);
00141     
00142     while (true) {
00143         led1 = !led1;
00144         Thread::wait(500);
00145     }
00146 }