hw3p2
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Revision 0:0f7c4e464135, committed 2015-02-24
- Comitter:
- lzzcd001
- Date:
- Tue Feb 24 14:34:00 2015 +0000
- Commit message:
- hw3p2
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Tue Feb 24 14:34:00 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Tue Feb 24 14:34:00 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Feb 24 14:34:00 2015 +0000 @@ -0,0 +1,111 @@ +#include "mbed.h" +#include "rtos.h" +#include "uLCD_4DGL.h" + +uLCD_4DGL lcd(p28, p27, p30); + +Mutex stdio_mutex; + +DigitalOut latch(p15); +DigitalOut enable(p16); +DigitalOut led1(LED1); + +SPI spi(p11, p12, p13); + +SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card + +AnalogOut DACout(p18); + +wave_player waver(&DACout); + +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 shiftbrite(void const *args) { + stdio_mutex.lock(); + int red=0; + int green=0; + int blue=0; + int r=1; + int g=1; + int b=1; + while(1) { + if (r == 1){ + if (red <= 255) {red += 5;} else {r= 1-r;} + } else { + if (red >= 0) {red -= 5;} else {r= 1-r;} + } + if (b == 1){ + if (blue <= 255) {blue += 5;} else {b=!b;} + } else { + if (blue >= 0) {blue -= 5;} else {b=!b;} + } + if (g == 1){ + if (green <= 255) {green += 5;} else {g=!g;} + } else { + if (green >= 0) {green -= 5;} else {g=!g;} + } + RGB_LED(red, green, blue); + stdio_mutex.unlock(); + wait(5); + } +} + +void lcd1(void const *args) { + stdio_mutex.lock(); + lcd.locate(0,0); + lcd.printf("police light"); + stdio_mutex.unlock(); + stdio_mutex.lock(); + for (int i=0; i<10; i++) { + lcd.locate(1,0); + lcd.printf("Counter: %d", i); + } + stdio_mutex.unlock(); + Thread:wait(2000); + //lcd.line(64,64,prevline_x,prevline_y, BLACK); + //lcd.circle(prevcirc_x,prevcirc_y, 10, BLACK); + //float line_x = 30*cos(heading*pi/180) + 64; + //float line_y = 30*sin(heading*pi/180) + 64; + //lcd.circle(64, 64, 30, GREEN); + //lcd.line(64,64,line_x, line_y, BLUE); +} + +void lcd2(void const *args) { + stdio_mutex.lock(); + lcd.locate(6,0); + lcd.printf("fire sound"); + stdio_mutex.unlock(); + Thread::wait(4000); + //lcd.line(64,64,prevline_x,prevline_y, BLACK); + //lcd.circle(prevcirc_x,prevcirc_y, 10, BLACK); + //float line_x = 30*cos(heading*pi/180) + 64; + //float line_y = 30*sin(heading*pi/180) + 64; + //lcd.circle(64, 64, 30, GREEN); + //lcd.line(64,64,line_x, line_y, BLUE); +} + +int main() { + spi.format(16,0); + spi.frequency(500000); + FILE *wave_file; + Thread t1(lcd1, (void *)"Th 1"); + Thread t2(lcd2, (void *)"Th 2"); + Thread t3(shiftbrite, (void *)"Th 3"); + + while (true) { + wave_file=fopen("/sd/test.wav","r"); + waver.play(wave_file); + fclose(wave_file); + led1 = !led1; + Theard::wait(1000); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Tue Feb 24 14:34:00 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#83e169389a69
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Feb 24 14:34:00 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Tue Feb 24 14:34:00 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad