4180 Final
Dependencies: mbed wave_player mbed-rtos 4180Final SDFileSystem
Diff: main.cpp
- Revision:
- 5:1e8b48d6682b
- Parent:
- 4:8331c1239f6a
- Child:
- 6:65216abe57c3
- Child:
- 9:c40418c26c04
--- a/main.cpp Mon Apr 27 19:30:53 2020 +0000 +++ b/main.cpp Mon Apr 27 20:35:13 2020 +0000 @@ -15,14 +15,14 @@ Nav_Switch myNav(p9, p6, p7, p5, p8); //pin order on Sparkfun breakout uLCD_4DGL uLCD(p28, p27, p30); // serial tx, serial rx, reset pin; PwmOut myled(LED1); -//SDFileSystem sd(p11, p12, p13, p10, "sd"); +SDFileSystem sd(p11, p12, p13, p10, "sd"); microphone mymic1(p15); AnalogIn pot(p16); AnalogOut DACout(p18); DigitalOut led(LED2); -//BusOut led_strip(p21, p22, p23, p24, p25, p26); +PwmOut myled3(LED3); -Thread thread1; +Thread thread1, thread2; // Stuff for sound unsigned char *music = NULL; @@ -44,6 +44,7 @@ int highScoresArr[10] = {100, 90, 83, 73, 64, 54, 44, 34, 24, 14}; int s = 0; int timer = 0; +volatile int micScore = 0; int main(); void play(); @@ -70,12 +71,20 @@ while (1) { if (timer == 99) { s = (int) (pot * 2.0); - myled = pot; } // Thread::wait(100); } } +// thread 2 +void mic_thread() { + while (1) { + myled = pot; + micScore = int(mymic1*1000.0); + Thread::wait(100); + } +} + void clearVals() { score1 = 0; score2 = 0; @@ -338,7 +347,8 @@ } int getScore1() { - return int(mymic1*1000.0); + myled3 = (int)(((float) micScore) / 1000.0); + return micScore; //int(mymic1*1000.0); // gameType==0 for mic @@ -349,26 +359,7 @@ // } } int getScore2() { - return mymic1*1000.0; -} - -void update_leds(float val){ - if(val <= 2.5){ - led_strip = 0b100000; - } else if (2.5 > val && val < 5){ - led_strip = 0b110000; - } else if (val > 5 && val < 7.5){ - led_strip = 0b111000; - } else if (val > 7.5 && val < 10){ - led_strip = 0b111100; - } else if (val > 10 && val < 12.5){ - led_strip = 0b111110; - } else if (val > 12.5 && val < 15){ - led_strip = 0b111111; - } else { - led_strip = 0; - } - Thread::wait(0.2); + return 10; //int(mymic1*1000.0); } void play() { @@ -410,7 +401,6 @@ if (timer % 25 == 0) { score1 = getScore1(); //(int) (pot*100.0); //curTime+1000; // int(mymic1*1000.0); score2 = getScore2(); //curTime+2000; - update_leds(getScore2()); uLCD.color(BLUE); uLCD.locate(0,1); uLCD.printf("%4d", score1); @@ -572,14 +562,14 @@ int main() { // read in highScoresArr from SD card - /*FILE *fp = fopen("/sd/finalProj/highscores.txt", "r"); + FILE *fp = fopen("/sd/finalProj/highscores.txt", "r"); if(fp == NULL) { uLCD.printf("Error Open \n"); } for (int i=0; i<sizeof(highScoresArr)/4; i++) { fscanf(fp, "%4d", &highScoresArr[i]); } - fclose(fp);*/ + fclose(fp); // create menu interface uLCD.background_color(LBLUE); uLCD.cls(); @@ -613,6 +603,7 @@ uLCD.filled_circle(xPos[i], yPos[i], 2, RED); } thread1.start(pot_thread); + thread2.start(mic_thread); nextsample.attach(&playMenuMusic, 1.0/8000.0); while (1) { // play music