Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos 4180Final SDFileSystem
Diff: main.cpp
- Revision:
- 3:ac5c3d483dbd
- Parent:
- 1:e14104308237
- Child:
- 4:e060ee6a74b5
--- a/main.cpp Sun Apr 26 19:18:46 2020 +0000 +++ b/main.cpp Mon Apr 27 05:12:43 2020 +0000 @@ -8,17 +8,30 @@ #include "Nav_Switch.h" #include "SDFileSystem.h" #include "microphone.h" + +#include "menumusic.h" +//#include "the_middle.h" +//#include "wave_player.h" #include "rtos.h" 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); Thread thread1; +// Stuff for sound +unsigned char *music = NULL; +//wave_player waver(&DACout); +Ticker nextsample; +volatile int sIndx = 0; +int playMusic = 0; + int rounds = 3; int curRound = 1; int score1 = 0; @@ -35,6 +48,23 @@ int main(); void play(); + + +void playMenuMusic() { + if (playMusic) { + music = (unsigned char*) menumusic; + led = 1; + DACout.write(music[sIndx++] / 255.0); + if(sIndx > 60000) { //120000 + sIndx = 0; + led = 0; + } + } else { + DACout.write(0.0); + sIndx = 0; + } +} + // thread1 void pot_thread() { while (1) { @@ -344,7 +374,7 @@ pause(); } if (timer % 25 == 0) { - score1 = get_sound(); //(int) (pot*100.0); //curTime+1000; // int(mymic1*1000.0); + score1 = (int) (pot*100.0); //curTime+1000; // int(mymic1*1000.0); score2 = curTime+2000; uLCD.color(BLUE); uLCD.locate(0,1); @@ -507,14 +537,14 @@ int main() { // read in highScoresArr from SD card - //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); + // 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); // create menu interface uLCD.background_color(LBLUE); uLCD.cls(); @@ -548,7 +578,10 @@ uLCD.filled_circle(xPos[i], yPos[i], 2, RED); } thread1.start(pot_thread); + nextsample.attach(&playMenuMusic, 1.0/8000.0); while (1) { + // play music + playMusic = 1; // Fill selector circle and if necessary, clear old if (oldTicker != ticker) { uLCD.filled_circle(xPos[oldTicker], yPos[oldTicker], 5+s, LBLUE); @@ -573,6 +606,7 @@ curTime = 0; score1 = 0; score2 = 0; + playMusic = 0; play(); break; case 1: