change in mbed rtos library

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

Fork of rtos_basic by mbed official

Committer:
bjs9
Date:
Wed Feb 28 09:54:23 2018 +0000
Revision:
13:b0bfe7f4472a
Parent:
12:fb46c68fa360
Changes to Lab3_Part31;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
mbed_official 11:0309bef74ba8 2 #include "rtos.h"
bjs9 12:fb46c68fa360 3 #include "uLCD_4DGL.h"
bjs9 12:fb46c68fa360 4 #include "RGB_LED.h"
bjs9 13:b0bfe7f4472a 5 #include "SDFileSystem.h"
bjs9 13:b0bfe7f4472a 6 #include "wave_player.h"
bjs9 12:fb46c68fa360 7
bjs9 12:fb46c68fa360 8
emilmont 1:491820ee784d 9 DigitalOut led1(LED1);
emilmont 1:491820ee784d 10 DigitalOut led2(LED2);
geky 7:8d9919175929 11 Thread thread;
bjs9 12:fb46c68fa360 12 Thread thread2;
bjs9 12:fb46c68fa360 13 Thread thread3;
bjs9 12:fb46c68fa360 14 Thread thread4;
bjs9 12:fb46c68fa360 15 Mutex stdio_mutex;
bjs9 13:b0bfe7f4472a 16 AnalogOut DACout(p18);
bjs9 13:b0bfe7f4472a 17 SDFileSystem sd(p5, p6, p7, p8, "sd");
bjs9 13:b0bfe7f4472a 18 Serial bluemod(p9,p10);
bjs9 13:b0bfe7f4472a 19 wave_player waver(&DACout);
bjs9 12:fb46c68fa360 20 uLCD_4DGL uLCD(p28,p27,p29);
bjs9 12:fb46c68fa360 21 RGBLed myRGBled(p22,p23,p24);
bjs9 13:b0bfe7f4472a 22 char bred=0;
bjs9 13:b0bfe7f4472a 23 char bgreen=0;
bjs9 13:b0bfe7f4472a 24 char bblue=0;
bjs9 13:b0bfe7f4472a 25 int bnum = 0;
bjs9 13:b0bfe7f4472a 26 int red=0;
bjs9 13:b0bfe7f4472a 27 int green=0;
bjs9 13:b0bfe7f4472a 28 int blue = 0;
bjs9 12:fb46c68fa360 29 void printName() {
bjs9 12:fb46c68fa360 30 stdio_mutex.lock();
bjs9 13:b0bfe7f4472a 31 uLCD.text_string("LETS DANCE!",1,14, FONT_7X8, RED);
bjs9 13:b0bfe7f4472a 32 Thread::wait(1000);
bjs9 13:b0bfe7f4472a 33 uLCD.text_string("LETS DANCE!",1,14, FONT_7X8, BLACK);
bjs9 13:b0bfe7f4472a 34 uLCD.text_string("TURN UP!",1,14,FONT_7X8, BLUE);
bjs9 12:fb46c68fa360 35 stdio_mutex.unlock();
bjs9 12:fb46c68fa360 36 }
bjs9 12:fb46c68fa360 37 void colorULCD() {
bjs9 12:fb46c68fa360 38 stdio_mutex.lock();
bjs9 12:fb46c68fa360 39 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 40 uLCD.filled_circle(60,60,20,RED);
bjs9 12:fb46c68fa360 41 Thread::wait(500);
bjs9 12:fb46c68fa360 42 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 43 uLCD.filled_circle(60,60,20,BLUE);
bjs9 12:fb46c68fa360 44 Thread::wait(500);
bjs9 12:fb46c68fa360 45 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 46 uLCD.filled_circle(60,60,20,RED);
bjs9 12:fb46c68fa360 47 Thread::wait(500);
bjs9 12:fb46c68fa360 48 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 49 uLCD.filled_circle(60,60,20, 255*65536+165*256+0);
bjs9 12:fb46c68fa360 50 Thread::wait(500);
bjs9 12:fb46c68fa360 51 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 52 uLCD.filled_circle(60,60,20,255*65536+255*256+0);
bjs9 12:fb46c68fa360 53 Thread::wait(500);
bjs9 12:fb46c68fa360 54 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 55 uLCD.filled_circle(60,60,20,GREEN);
bjs9 12:fb46c68fa360 56 Thread::wait(500);
bjs9 12:fb46c68fa360 57 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 58 uLCD.filled_circle(60,60,20,BLUE);
bjs9 12:fb46c68fa360 59 Thread::wait(500);
bjs9 12:fb46c68fa360 60 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 61 uLCD.filled_circle(60,60,20,75*65536+0*256+130);
bjs9 12:fb46c68fa360 62 Thread::wait(500);
bjs9 12:fb46c68fa360 63 uLCD.line(60,80,60,0,128*65536+128*256+128);
bjs9 12:fb46c68fa360 64 uLCD.filled_circle(60,60,20,128*65536+0*256+128);
bjs9 12:fb46c68fa360 65 stdio_mutex.unlock();
bjs9 12:fb46c68fa360 66 }
emilmont 1:491820ee784d 67
bjs9 13:b0bfe7f4472a 68 void RGB_LED() {
bjs9 13:b0bfe7f4472a 69
bjs9 13:b0bfe7f4472a 70 if (bluemod.getc()=='!') {
bjs9 13:b0bfe7f4472a 71 if (bluemod.getc()=='C') { //color data packet
bjs9 13:b0bfe7f4472a 72 stdio_mutex.lock();
bjs9 13:b0bfe7f4472a 73 bred = bluemod.getc(); // RGB color values
bjs9 13:b0bfe7f4472a 74 bgreen = bluemod.getc();
bjs9 13:b0bfe7f4472a 75 bblue = bluemod.getc();
bjs9 13:b0bfe7f4472a 76 if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) {
bjs9 13:b0bfe7f4472a 77 //checksum OK?
bjs9 13:b0bfe7f4472a 78 stdio_mutex.unlock();
bjs9 13:b0bfe7f4472a 79 red = bred/255.0; //send new color to RGB LED PWM outputs
bjs9 13:b0bfe7f4472a 80 green = bgreen/255.0;
bjs9 13:b0bfe7f4472a 81 blue = bblue/255.0;
bjs9 13:b0bfe7f4472a 82 myRGBled.write(red,green,blue);
bjs9 13:b0bfe7f4472a 83 }
bjs9 13:b0bfe7f4472a 84 }
bjs9 13:b0bfe7f4472a 85 }
bjs9 13:b0bfe7f4472a 86 }
bjs9 13:b0bfe7f4472a 87 void Speaker_Function() {
bjs9 13:b0bfe7f4472a 88 FILE *wave_file;
bjs9 13:b0bfe7f4472a 89
bjs9 13:b0bfe7f4472a 90 if (bluemod.getc()=='!') {
bjs9 13:b0bfe7f4472a 91 if (bluemod.getc()=='B') { //button data
bjs9 13:b0bfe7f4472a 92 stdio_mutex.lock();
bjs9 13:b0bfe7f4472a 93 bnum = bluemod.getc();
bjs9 13:b0bfe7f4472a 94 stdio_mutex.unlock();
bjs9 13:b0bfe7f4472a 95 if (bnum=='1') { //is a number button 1..4
bjs9 13:b0bfe7f4472a 96 wave_file=fopen("/sd/wavfiles/trapman.wav","r");
bjs9 13:b0bfe7f4472a 97 waver.play(wave_file);
bjs9 13:b0bfe7f4472a 98 fclose(wave_file); //turn on/off that num LED
bjs9 13:b0bfe7f4472a 99 }
bjs9 13:b0bfe7f4472a 100 }
bjs9 13:b0bfe7f4472a 101 }
bjs9 13:b0bfe7f4472a 102 }
bjs9 13:b0bfe7f4472a 103 //myRGBled.write(1.0f, 0, 0); // turn the RGB LED red
bjs9 13:b0bfe7f4472a 104 //Thread::wait(500); // wait for 1 second
bjs9 13:b0bfe7f4472a 105 //myRGBled.write(0, 0, 255); // turn the RGB LED blue
bjs9 13:b0bfe7f4472a 106 //Thread::wait(500); // wait for 1 second
bjs9 13:b0bfe7f4472a 107 // Example blended myRGBled.writes:
bjs9 13:b0bfe7f4472a 108 //myRGBled.write(255,0,0); // turn the RGB LED red
bjs9 13:b0bfe7f4472a 109 //Thread::wait(500); // wait for 1 second
bjs9 13:b0bfe7f4472a 110 //myRGBled.write(237,109,0); // turn the RGB LED orange
bjs9 13:b0bfe7f4472a 111 //Thread::wait(500); // wait for 1 second
bjs9 13:b0bfe7f4472a 112 //myRGBled.write(255,215,0); // turn the RGB LED yellow
bjs9 13:b0bfe7f4472a 113 //Thread::wait(500); // wait for 1 second
bjs9 13:b0bfe7f4472a 114 //myRGBled.write(34,139,34); // turn the RGB LED green
bjs9 13:b0bfe7f4472a 115 //Thread::wait(500); // wait for 1 second
bjs9 13:b0bfe7f4472a 116 //myRGBled.write(0,0,255); // turn the RGB LED blue
bjs9 13:b0bfe7f4472a 117 //Thread::wait(050); // wait for 1 second
bjs9 13:b0bfe7f4472a 118 //myRGBled.write(0,46,90); // turn the RGB LED indigo
bjs9 13:b0bfe7f4472a 119 //Thread::wait(500); // wait for 1 second
bjs9 13:b0bfe7f4472a 120 //myRGBled.write(128,0,128); // turn the RGB LED purple
bjs9 12:fb46c68fa360 121 void uLCD_thread1() {
bjs9 12:fb46c68fa360 122 while (true) {
bjs9 12:fb46c68fa360 123 colorULCD();
bjs9 12:fb46c68fa360 124 Thread::wait(500);
bjs9 12:fb46c68fa360 125 }
bjs9 12:fb46c68fa360 126
bjs9 12:fb46c68fa360 127 }
bjs9 12:fb46c68fa360 128 void uLCD_thread2() {
emilmont 1:491820ee784d 129 while (true) {
bjs9 12:fb46c68fa360 130 printName();
bjs9 13:b0bfe7f4472a 131 Thread::wait(250);
emilmont 1:491820ee784d 132 }
bjs9 12:fb46c68fa360 133
bjs9 12:fb46c68fa360 134 }
bjs9 13:b0bfe7f4472a 135 void RGB_thread3(){
bjs9 13:b0bfe7f4472a 136 while (true){
bjs9 13:b0bfe7f4472a 137 RGB_LED();
bjs9 13:b0bfe7f4472a 138 Thread::wait(100);
bjs9 13:b0bfe7f4472a 139 }
bjs9 12:fb46c68fa360 140 }
bjs9 13:b0bfe7f4472a 141 void Speaker_Thread(){
bjs9 13:b0bfe7f4472a 142 while(true){
bjs9 13:b0bfe7f4472a 143 Speaker_Function();
bjs9 13:b0bfe7f4472a 144 Thread::wait(250);
bjs9 13:b0bfe7f4472a 145 }
bjs9 13:b0bfe7f4472a 146 }
bjs9 12:fb46c68fa360 147 int main() {
bjs9 13:b0bfe7f4472a 148 // thread.start(uLCD_thread1);
bjs9 13:b0bfe7f4472a 149 thread2.start(uLCD_thread2);
bjs9 13:b0bfe7f4472a 150 thread3.start(RGB_thread3);
bjs9 13:b0bfe7f4472a 151 thread4.start(Speaker_Thread);
bjs9 13:b0bfe7f4472a 152 // FILE *wave_file;
bjs9 13:b0bfe7f4472a 153 // wave_file=fopen("/sd/wavfiles/trapman.wav","r");
bjs9 13:b0bfe7f4472a 154 // waver.play(wave_file);
bjs9 13:b0bfe7f4472a 155 // fclose(wave_file);
emilmont 1:491820ee784d 156 }
bjs9 13:b0bfe7f4472a 157
bjs9 13:b0bfe7f4472a 158
bjs9 13:b0bfe7f4472a 159