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 wave_player mbed-rtos 4180Final SDFileSystem
Diff: main.cpp
- Revision:
- 3:927028389e55
- Parent:
- 1:e14104308237
- Child:
- 4:8331c1239f6a
--- a/main.cpp Sun Apr 26 19:18:46 2020 +0000
+++ b/main.cpp Mon Apr 27 05:25:27 2020 +0000
@@ -8,17 +8,29 @@
#include "Nav_Switch.h"
#include "SDFileSystem.h"
#include "microphone.h"
+#include "fireflies.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;
+
+// Globals
int rounds = 3;
int curRound = 1;
int score1 = 0;
@@ -35,6 +47,23 @@
int main();
void play();
+
+// Method for ticker for sound
+void playMenuMusic() {
+ if (playMusic) {
+ music = (unsigned char*) fireflies;
+ led = 1;
+ DACout.write(music[sIndx++] / 255.0);
+ if(sIndx > 120000) {
+ sIndx = 0;
+ led = 0;
+ }
+ } else {
+ DACout.write(0.0);
+ sIndx = 0;
+ }
+}
+
// thread1
void pot_thread() {
while (1) {
@@ -307,6 +336,21 @@
}
}
+int getScore1() {
+ return int(mymic1*1000.0);
+
+
+ // gameType==0 for mic
+ //if (gameType == 0) {
+//
+// } else {
+//
+// }
+}
+int getScore2() {
+ return int(mymic1*1000.0);
+}
+
void play() {
uLCD.background_color(GREEN);
uLCD.cls();
@@ -344,8 +388,8 @@
pause();
}
if (timer % 25 == 0) {
- score1 = get_sound(); //(int) (pot*100.0); //curTime+1000; // int(mymic1*1000.0);
- score2 = curTime+2000;
+ score1 = getScore1(); //(int) (pot*100.0); //curTime+1000; // int(mymic1*1000.0);
+ score2 = getScore2(); //curTime+2000;
uLCD.color(BLUE);
uLCD.locate(0,1);
uLCD.printf("%4d", score1);
@@ -507,14 +551,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 +592,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 +620,7 @@
curTime = 0;
score1 = 0;
score2 = 0;
+ playMusic = 0;
play();
break;
case 1: