From 80d1535f029de6c8474d74d4fd468c1d789935ef Mon Sep 17 00:00:00 2001 From: Mike S Date: Thu, 30 Jan 2014 16:18:28 -0700 Subject: [PATCH] Added Combo Lock Code --- Firmware/Combo/Combo.ino | 87 ++++++++++++++++++++++ Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino | 16 +++- 2 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 Firmware/Combo/Combo.ino diff --git a/Firmware/Combo/Combo.ino b/Firmware/Combo/Combo.ino new file mode 100644 index 0000000..c505561 --- /dev/null +++ b/Firmware/Combo/Combo.ino @@ -0,0 +1,87 @@ +/* + Make the Simon Says Game a 4-hole Ocarina (Like in the legend of zelda) + + Prof Mike Soltys + University of Colorado + 1/28/2014 + */ + + +// 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. +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() { + // 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. + + // Start with all buttons pressed - C4 - 262 + int Button=ButtonWait(); + delay(100); + if (Button == 1){ + digitalWrite(led_UL, HIGH); + Button=ButtonWait(); + if (Button==2){ + digitalWrite(led_UR, HIGH); + } + } + delay(1000); + digitalWrite(led_UR, LOW); + digitalWrite(led_UL, LOW); + digitalWrite(led_LL, LOW); + digitalWrite(led_LR, LOW); +} + +int ButtonWait(void){ +while(1 == 1){ + if(digitalRead(but_UL) == 0){ + while (digitalRead(but_UL) != 0) ; + delay(10); + return 1; + } + else if(digitalRead(but_UR) == 0){ + while (digitalRead(but_UR) != 0) ; + delay(10); + return 2; + } + else if(digitalRead(but_LL) == 0){ + while (digitalRead(but_LL) != 0) ; + delay(10); + return 3; + } + else if(digitalRead(but_LR) == 0){ + while (digitalRead(but_LR) != 0) ; + delay(10); + return 4; + } + } +} diff --git a/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino b/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino index 7ae8c2a..1effc7d 100644 --- a/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino +++ b/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino @@ -36,8 +36,9 @@ int buzzer_2 = 7; void setup() { pinMode(ledPin, OUTPUT); - digitalWrite(buttonPin, HIGH); - pinMode(buttonPin, INPUT); + // Note: For the way the circuit is setup, INPUT_PULLUP will result much more + // stability than INPUT + pinMode(buttonPin, INPUT_PULLUP); pinMode(buzzer_1, OUTPUT); pinMode(buzzer_2, OUTPUT); @@ -51,14 +52,21 @@ void loop() int button_state = digitalRead(buttonPin); - if(button_state == 1){ + if(button_state == 0){ digitalWrite(ledPin, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(ledPin, LOW); // set the LED off // Call the "buzz()" funtion. See below to know what this does. - buzz(); + tone(buzzer_1,400,500); + delay(1000); + tone(buzzer_2,600,500); + delay(1000); + tone(buzzer_1,400,500); + delay(250); + tone(buzzer_2,600,500); + //tone(buzzer_1,500,100); }