HW2_2
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
Fork of rtos_mutex by
Diff: main.cpp
- Revision:
- 5:08ccfbd78092
- Parent:
- 1:0f886ffbe0c1
--- a/main.cpp Tue Jun 04 16:03:01 2013 +0100 +++ b/main.cpp Mon Feb 23 15:05:26 2015 +0000 @@ -1,24 +1,86 @@ #include "mbed.h" #include "rtos.h" +#include "uLCD_4DGL.h" + +uLCD_4DGL lcd(p28, p27, p30); Mutex stdio_mutex; -void notify(const char* name, int state) { - stdio_mutex.lock(); - printf("%s: %d\n\r", name, state); - stdio_mutex.unlock(); +DigitalOut latch(p15); +DigitalOut enable(p16); +DigitalOut led1(LED1); + +SPI spi(p11, p12, p13); + +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 test_thread(void const *args) { - while (true) { - notify((const char*)args, 0); Thread::wait(1000); - notify((const char*)args, 1); Thread::wait(1000); +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.printf("music playing"); + stdio_mutex.unlock(); + //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() { - Thread t2(test_thread, (void *)"Th 2"); - Thread t3(test_thread, (void *)"Th 3"); + spi.format(16,0); + spi.frequency(500000); + enable=0; + latch=0; + Thread t1(lcd1, (void *)"Th 1"); + Thread t2(shiftbrite, (void *)"Th 2"); - test_thread((void *)"Th 1"); + while (true) { + led1 = !led1; + Thread::wait(10); + } + + //Thread t3(test_thread, (void *)"Th 3"); + + //test_thread((void *)"Th 1"); } + +