Complete Build
Dependencies: 4DGL-uLCD-SE1 Motor SDFileSystem X_NUCLEO_53L0A1 mbed-rtos mbed BotwithWavePlayerLevel
Fork of BotWithBluetoothLIDARV2 by
Diff: main.cpp
- Revision:
- 14:cc2e4fbaffd8
- Parent:
- 13:ab6bbdd2447a
- Child:
- 15:c8360ceaad61
--- a/main.cpp Fri Oct 06 04:33:17 2017 +0000 +++ b/main.cpp Mon Oct 09 21:04:05 2017 +0000 @@ -6,6 +6,7 @@ //nclude "picojpeg.h" Serial blues(p13,p14); +Serial pc(USBTX, USBRX); SDFileSystem sd(p5, p6, p7, p9, "sd"); //SD card AnalogOut DACout(p18); @@ -23,12 +24,20 @@ Thread thread3; Thread thread4; Thread thread5; +Thread thread6; float y=0.0; int c=80; int d=1; char bnum=0; char current='1'; int color=YELLOW; + +char previousButton; + +double w; //Angular frequency of sinusoidal wave controlling RGB LED +double k; + +FILE *wave_file; void t2() { while (true) { @@ -38,7 +47,7 @@ ourMutex.lock(); uLCD.background_color(BLACK); uLCD.cls(); - uLCD.filled_circle(a, 80-(y*80)+25, r, BLUE); + uLCD.filled_circle(a, 105-(y*80), r, BLUE); uLCD.line(3,25,13,25,RED); uLCD.line(3,105,13,105,RED); ourMutex.unlock(); @@ -66,7 +75,7 @@ void t3() { while (true) { - FILE *wave_file; + wave_file=fopen("/sd/Bee Gees - Stayin' Alive.wav","r"); waver.play(wave_file); @@ -75,6 +84,16 @@ } } + void t6() { + while (true) { + + wave_file=fopen("/sd/Joey Scarbury - Believe it or Not.wav","r"); + waver.play(wave_file); + fclose(wave_file); + Thread::wait(1000); + } +} + void t4() { while (true) { @@ -105,6 +124,9 @@ void t5(){ + char bhit = 0; + //double d = 10; + while(true){ @@ -113,30 +135,80 @@ if (blues.getc()=='!') { if (blues.getc()=='B') { //button data bnum = blues.getc(); //button number - if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4 + bhit = blues.getc(); //button hit = 1; miss = 0; + + if ((bnum>='1')&&(bnum<='8')){ //is a number button 1..4 current=bnum; - } - } - - } + //pc.printf("Button Pressed %c bhit = %c PreviousButton = %c CurrentButton = %c\n\r", bnum, bhit, previousButton, current); + previousButton = current; + if(current=='1'){ + color=YELLOW; + } + if(current=='2'){ + color=BLUE; + } + if(current=='3'){ + color=0x551A8B; //Purple + } + if(current=='4'){ + color=GREEN; + } + if(current =='5' && bhit == '0'){ + color=BLACK; + thread3.terminate(); + //thread3.join(); + fclose(wave_file); + if(wave_file != NULL){ + pc.printf("after close t3, file is not NULL\n\r"); + } + Thread::wait(100); + thread6.start(t6); + } + + if(current =='6' && bhit == '0'){ + color=RED; + thread6.terminate(); + //thread6.join(); + fclose(wave_file); + if(wave_file != NULL){ + pc.printf("after close t6, file is not NULL\n\r"); + } + Thread::wait(100); + thread3.start(t3); + } + if(current =='8' && bhit == '0'){ + color=ORANGE; + k = k*2; + if(k > 8.0){ + k = 8.0; + } + + + } + if(current =='7' && bhit == '0'){ + color=0x00FFFF; + k = k*0.5; + + if(k < 0.125){ + k = 0.125; + } + + } + + + }//end of if bnum 1 -8 + }//end of if getc B + }//end of if getc ! - if(current=='1'){ - color=YELLOW; - } - if(current=='2'){ - color=BLUE; - } - if(current=='3'){ - color=0x551A8B; - } - if(current=='4'){ - color=GREEN; - } + }// end of if readable + + + ourMutex.unlock(); Thread::wait(50); - } + }// end of while loop } @@ -149,18 +221,22 @@ thread4.start(t4); thread5.start(t5); + previousButton = '0'; + + k = 1.0; while(1) { - for(double x=0.0; x <= 3.14159; x = x + 0.0314159) { - y = sin(x); + for(double x=0.0; x <= 100/k; x = x + 1) { + w = 3.14159*k/100.0; + y = sin(w*x); red= y*y*y; blue= y*y*y; green= y*y*y; Thread::wait(1000.0*.025); } - red= 0.0; - blue= 0.0; - green= 0.0; - Thread::wait(1000.0*2.5); + //red= 0.0; + //blue= 0.0; + //green= 0.0; + //Thread::wait(1000.0*2.5/w); }