Simon-Says/Firmware/Additional Experiments/Ocarina/Ocarina.ino

122 lines
3.5 KiB
Arduino
Raw Normal View History

2014-01-28 21:51:31 -07:00
/*
Make the Simon Says Game a 4-hole Ocarina (Like in the legend of zelda)
2014-01-28 21:54:25 -07:00
Prof Mike Soltys
University of Colorado
1/28/2014
2014-01-28 21:51:31 -07:00
*/
2014-01-28 21:54:25 -07:00
// Define the button, LED, and buzzer pins (this is standard for all Simon Says games
// I've labeled mine UL for Upper Left, LR for Lower Left and so on.
2014-01-28 21:51:31 -07:00
const int led_UL = 10; //Red
const int led_UR = 3; //Green
const int led_LL = 13; //Blue
const int led_LR = 5; //Yellow
const int but_UL = 9;
const int but_UR = 2;
const int but_LL = 12;
const int but_LR = 6;
const int BUZZER1 = 4;
const int BUZZER2 = 7;
void setup() {
//Setup hardware inputs/outputs.
//Enable pull ups on inputs
pinMode(but_UL, INPUT_PULLUP);
pinMode(but_UR, INPUT_PULLUP);
pinMode(but_LL, INPUT_PULLUP);
pinMode(but_LR, INPUT_PULLUP);
pinMode(led_UL, OUTPUT);
pinMode(led_UR, OUTPUT);
pinMode(led_LL, OUTPUT);
pinMode(led_LR, OUTPUT);
pinMode(BUZZER1, OUTPUT);
pinMode(BUZZER2, OUTPUT);
}
void loop() {
2014-01-28 22:05:14 -07:00
// keep doing this over and over again.
// I will start with the most buttons pressed, and move on to the least buttons pressed
// for any combination, i'll play a matching note and light up the LEDs that aren't being pressed.
2014-01-28 21:51:31 -07:00
// Start with all buttons pressed - C4 - 262
if (digitalRead(but_UL) == 0 && digitalRead(but_UR) == 0 && digitalRead(but_LL) == 0 && digitalRead(but_LR) == 0) {
tone(BUZZER2,262,50);
}
2014-01-28 22:05:14 -07:00
// uncover upper right only - D4 - 294
2014-01-28 21:51:31 -07:00
else if (digitalRead(but_UL) == 0 && digitalRead(but_LL) == 0 && digitalRead(but_LR) == 0) {
digitalWrite(led_UR, HIGH);
tone(BUZZER2,294,50);
}
2014-01-28 22:05:14 -07:00
// uncover lower right only - E4 -330
2014-01-28 21:51:31 -07:00
else if (digitalRead(but_UL) == 0 && digitalRead(but_UR) == 0 && digitalRead(but_LL) == 0) {
tone(BUZZER2,330,50);
digitalWrite(led_LR, HIGH);
}
2014-01-28 22:05:14 -07:00
// uncover upper left only - F4# -370
2014-01-28 21:51:31 -07:00
else if (digitalRead(but_UR) == 0 && digitalRead(but_LL) == 0 && digitalRead(but_LR) == 0) {
digitalWrite(led_UL, HIGH);
tone(BUZZER2,370,50);
}
// uncover both right - F4 -349
else if (digitalRead(but_UL) == 0 && digitalRead(but_LL) == 0) {
digitalWrite(led_UR, HIGH);
digitalWrite(led_LR, HIGH);
tone(BUZZER2,349,50);
}
// uncover both top - G4 -392
else if (digitalRead(but_LL) == 0 && digitalRead(but_LR) == 0) {
digitalWrite(led_UR, HIGH);
digitalWrite(led_UL, HIGH);
tone(BUZZER2,392,50);
}
// uncover upper left and lower right - G4# -415
else if (digitalRead(but_LL) == 0 && digitalRead(but_UR) == 0) {
digitalWrite(led_LR, HIGH);
digitalWrite(led_UL, HIGH);
tone(BUZZER2,415,50);
}
// cover LL only - A4 -440
else if (digitalRead(but_LL) == 0) {
digitalWrite(led_UR, HIGH);
digitalWrite(led_UL, HIGH);
digitalWrite(led_LR, HIGH);
tone(BUZZER2,440,50);
}
// cover LR only - A4# -466
else if (digitalRead(but_LR) == 0) {
digitalWrite(led_UR, HIGH);
digitalWrite(led_UL, HIGH);
digitalWrite(led_LL, HIGH);
tone(BUZZER2,466,50);
}
// cover UR only - B4 -494
else if (digitalRead(but_UR) == 0) {
digitalWrite(led_UL, HIGH);
digitalWrite(led_LL, HIGH);
digitalWrite(led_LR, HIGH);
tone(BUZZER2,494,50);
}
// all open - C5 -523
else {
digitalWrite(led_UL, HIGH);
digitalWrite(led_UR, HIGH);
digitalWrite(led_LL, HIGH);
digitalWrite(led_LR, HIGH);
tone(BUZZER2,523,50);
}
2014-01-28 21:54:25 -07:00
2014-01-28 22:05:14 -07:00
// Turn off all LEDs (This will happen so quick before
// the next iteration through the loop, that you'll never notice it_
2014-01-28 21:51:31 -07:00
digitalWrite(led_UR, LOW);
digitalWrite(led_UL, LOW);
digitalWrite(led_LL, LOW);
digitalWrite(led_LR, LOW);
}