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:
- 4:d414aee7ce9d
- Parent:
- 3:07afde41e7e6
- Child:
- 5:e297f321fa20
diff -r 07afde41e7e6 -r d414aee7ce9d main.cpp
--- a/main.cpp Sun Apr 21 11:32:02 2019 +0000
+++ b/main.cpp Fri Apr 26 07:28:26 2019 +0000
@@ -17,7 +17,7 @@
PwmOut speaker(p21);
// I2C to drive LED srips
-I2C i2c(p9, p10);
+I2C i2cLED(p9, p10);
// LED for tests
DigitalOut testLED(LED1);
@@ -30,6 +30,7 @@
int prevNote;
int mode;
int numModes;
+int score;
bool needNote;
const int addr = 0b0100000 << 1;
char cmd[2];
@@ -39,13 +40,14 @@
void variableInit() {
// modes
mode = 0;
- numModes = 2;
+ numModes = 3;
switchPressed = false;
// keys
notePressed = false;
prevNote = -1;
// wack-a-mole
needNote = true;
+ score = 0;
}
void buttonSetup() {
@@ -135,6 +137,9 @@
if (butMode == 0) {
if (!switchPressed) {
switchPressed = true;
+ prevNote = -1;
+ score = 0;
+
mode++;
if (mode == numModes) {
mode = 0;
@@ -169,6 +174,39 @@
speaker = 0;
count++;
if (count == 8) {count = 0;}
+ prevNote = count;
+}
+
+void lightLED(int key) {
+ switch(key) {
+ case 0:
+ cmd[0] = 0xFE;
+ break;
+ case 1:
+ cmd[0] = 0xFD;
+ break;
+ case 2:
+ cmd[0] = 0xFB;
+ break;
+ case 3:
+ cmd[0] = 0xF7;
+ break;
+ case 4:
+ cmd[0] = 0x7F;
+ break;
+ case 5:
+ cmd[0] = 0xBF;
+ break;
+ case 6:
+ cmd[0] = 0xDF;
+ break;
+ case 7:
+ cmd[0] = 0xEF;
+ break;
+ default:
+ cmd[0] = 0xFF;
+ }
+ i2cLED.write(addr, cmd, 1);
}
int main() {
@@ -176,11 +214,17 @@
buttonSetup();
while(1) {
+
+ lightLED(prevNote);
switchModeCheck();
if (mode == 0) {
+ testLED = 0; // remove once whac-a-mole is implemented
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
cycleSound();
}
}
