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 SDFileSystem
Diff: main.cpp
- Revision:
- 6:7f0a090b12e2
- Parent:
- 5:e297f321fa20
- Child:
- 7:af45a10fdfb6
--- a/main.cpp Fri Apr 26 15:30:05 2019 +0000
+++ b/main.cpp Fri Apr 26 23:56:19 2019 +0000
@@ -44,6 +44,9 @@
int numModes;
int score;
bool needNote;
+bool pianoMode;
+bool hitNote;
+int targetNote;
const int addr = 0b0100000 << 1;
char cmd[2];
@@ -57,9 +60,12 @@
// keys
notePressed = false;
prevNote = -1;
+ pianoMode = true;
// wack-a-mole
needNote = true;
score = 0;
+ targetNote = -1;
+ hitNote = false;
}
void buttonSetup() {
@@ -115,7 +121,7 @@
// this if statement initializes first note sound
if (!notePressed) {
if (butC == 0) {
- speaker.period(1.0/523.25);
+ speaker.period(1.0/523.25);
prevNote = 0;
} else if (butD == 0) {
speaker.period(1.0/587.33);
@@ -141,11 +147,25 @@
}
}
notePressed = true;
- speaker = 0.5;
+ if (pianoMode) {
+ speaker = 0.5;
+ } else {
+ if (prevNote == targetNote) {
+ speaker = 0.5;
+ hitNote = true;
+ }
+ }
} else {
- notePressed = false;
- speaker = 0;
- prevNote = -1;
+ notePressed = false;
+ speaker = 0;
+ prevNote = -1;
+ if (!pianoMode) {
+ if (hitNote) {
+ needNote = true;
+ hitNote = false;
+ score++;
+ }
+ }
}
}
@@ -155,10 +175,16 @@
switchPressed = true;
prevNote = -1;
score = 0;
+ needNote = true;
+ targetNote = rand() % 8;
+
+ pianoMode = false;
+ hitNote = false;
mode++;
if (mode == numModes) {
mode = 0;
+ pianoMode = true;
}
}
} else {
@@ -225,6 +251,15 @@
i2cLED.write(addr, cmd, 1);
}
+void playWhackAMole() {
+ if (needNote) {
+ targetNote = rand() % 8;
+ needNote = false;
+ lightLED(targetNote);
+ }
+ pressKey(); // rest of checks are in this function
+}
+
void testSd(){
pc.printf("Kevin sucks\n");
mkdir("/sd/mydir", 0777);
@@ -252,23 +287,22 @@
buttonSetup();
speakerSetup();
wait(0.5);
- testSd();
- testSpeaker();
- // testSd();
+
+// testSd();
+// testSpeaker();
+// testSd();
while(1) {
-
- lightLED(prevNote);
switchModeCheck();
- if (mode == 0) {
- testLED = 0; // remove once whac-a-mole is implemented
+ if (mode == 0) { // PIANO MODE
pressKey();
- } else if (mode == 1) {
- testLED = 1; // remove once whac-a-mole is implemented
- } else if (mode == 2) {
- testLED = 0; // remove once whac-a-mole is implemented
+ lightLED(prevNote);
+ } else if (mode == 1) { // WHACK A MOLE MODE
+ playWhackAMole();
+ } else if (mode == 2) { // CYCLE SOUNDS MODE
cycleSound();
+ lightLED(prevNote);
}
}
}
\ No newline at end of file
