adfdadf
Dependencies: SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE ShiftBrite
Fork of rtos_mutex by
main.cpp
- Committer:
- ashea6
- Date:
- 2016-02-26
- Revision:
- 6:91595eac48f4
- Parent:
- 1:0f886ffbe0c1
- Child:
- 7:2122726e9b46
File content as of revision 6:91595eac48f4:
#include "mbed.h" #include "rtos.h" #include "SDFileSystem.h" #include "wave_player.h" //additional for Lab4 //#include "PinDetect.h" #include "uLCD_4DGL.h" #include <vector> #include <string> #include "ShiftBrite.h" uLCD_4DGL uLCD(p28,p27,p29); // create a global LCD object //uLCD_4DGL uLCD(p28, p27, p29); SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card DigitalIn detectSD(p12); //connect CD AnalogOut DACout(p18); //speaker wave_player waver(&DACout); //wave player library //DigitalOut latch(p15); //DigitalOut enable(p16); SPI spi(p11, p12, p13); DigitalOut led1(LED1); DigitalOut led2(LED2); ShiftBrite myBrite(p15,p16,spi); //latch, enable, spi Mutex stdio_mutex; //shiftbrite /*void RGB_LED(int red, int green, int blue) { unsigned int low_color=0; unsigned int high_color=0; high_color=(blue<<4)|((red&0x3C0)>>6); low_color=(((red&0x3F)<<10)|(green)); spi.write(high_color); spi.write(low_color); latch=1; latch=0; } */ void wav_thread(void const *args) { FILE *wave_file; printf("\n\n\nHello, wave world!\n"); wave_file=fopen("/sd/beethoven.wav","r"); //while(1){ waver.play(wave_file); //} fclose(wave_file); } void shift_thread(void const *args){ int r,g,b; r=g=b=50; while(1) { myBrite.Write(255,255,255); Thread::wait(500); myBrite.Write(0,0,255); Thread::wait(500); myBrite.Write(0,255,0); Thread::wait(500); myBrite.Write(255,0,0); Thread::wait(500); myBrite.Brightness(r,g,b); if(r<1023) r+=50; else r=50; g=b=r; } } void led2_thread(void const *args) { while (true) { led2 = !led2; Thread::wait(1000); } } 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); } } int main() { Thread wav_thread(wav_thread); Thread thread(led2_thread); Thread shift_thread(shift_thread); while (true) { led1 = !led1; Thread::wait(500); } Thread t2(test_thread, (void *)"Th 2"); Thread t3(test_thread, (void *)"Th 3"); test_thread((void *)"Th 1"); }