diff --git a/Firmware/SIMON_1_BLINK/SIMON_1_BLINK.ino b/Firmware/SIMON_1_BLINK/SIMON_1_BLINK.ino index 99e9433..c44fe40 100644 --- a/Firmware/SIMON_1_BLINK/SIMON_1_BLINK.ino +++ b/Firmware/SIMON_1_BLINK/SIMON_1_BLINK.ino @@ -8,7 +8,8 @@ Sparkfun Electronics Modified by Prof Mike Soltys -01/15/2013 +University of Colorado +01/15/2014 This example code is in the public domain. diff --git a/Firmware/SIMON_2_BUTTON/SIMON_2_BUTTON.pde b/Firmware/SIMON_2_BUTTON/SIMON_2_BUTTON.ino old mode 100755 new mode 100644 similarity index 73% rename from Firmware/SIMON_2_BUTTON/SIMON_2_BUTTON.pde rename to Firmware/SIMON_2_BUTTON/SIMON_2_BUTTON.ino index 18fd0b4..885072c --- a/Firmware/SIMON_2_BUTTON/SIMON_2_BUTTON.pde +++ b/Firmware/SIMON_2_BUTTON/SIMON_2_BUTTON.ino @@ -6,6 +6,10 @@ Pete Lewis Sparkfun Electronics 10/13/2010 +Modified by +Prof Mike Soltys +University of Colorado +01/15/14 This example code is in the public domain. ////////////////////////////////////////////////// @@ -16,6 +20,13 @@ SETUP & UPLOAD INSTRUCTIONS 4. Click on the "upload button" - it looks like a box with an arrow to the right. ////////////////////////////////////////////////// +////////////////////////////////////////////////// +DESCRIPTION +Pressing the buttion will change the state of the LED from on to off or off to on. + +Note: these buttions are SUPER sensitive (freakishly so). The simon says code usese +a delay and check process called debouncing to fix this. +////////////////////////////////////////////////// */ @@ -33,7 +44,8 @@ int buttonPin = 2; // The simon board has 4 BUTTONS on it. int button_state; // This variable will be used to "store" the state of the button. // It will allow us to know whether the button is pressed or not. - +int led_state = 0; // This variable will be used to "store" the state of the LED. + // It will allow us to know whether the LED is on or off. // The setup() funtion runs once, when the sketch starts void setup() { @@ -61,9 +73,17 @@ void loop() // The second step in the loop is to actually do something with this variable. // In this next "if statement" we are going to decide to do something. Here we are going to turn on the ledPin for a second. if(button_state == 1){ - digitalWrite(ledPin, HIGH); // set the LED on - delay(1000); // wait for a second - digitalWrite(ledPin, LOW); // set the LED off + // If the LED is off, turn it on + if (led_state == 0 ){ + digitalWrite(ledPin, HIGH); // set the LED on + led_state = 1; + } + // If the LED is on, turn it off + else if (led_state == 1 ) { + digitalWrite(ledPin, LOW); // set the LED off + led_state = 0; + } + delay(1000); // wait for a second } } diff --git a/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.pde b/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino old mode 100755 new mode 100644 similarity index 80% rename from Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.pde rename to Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino index 91e6fd5..7ae8c2a --- a/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.pde +++ b/Firmware/SIMON_3_BUZZER/SIMON_3_BUZZER.ino @@ -1,12 +1,25 @@ /* -Simon Experiments #2 +Simon Experiments #3 Buzzer Pete Lewis Sparkfun Electronics 10/13/2010 +Updated by +Prof Mike Soltys +University of Colorado +01/15/2014 + This example code is in the public domain. +////////////////////////////////////////////////// +DESCRIPTION +Pressing the buttion will flash the LED for 1 second and play a tone. + +Note: these buttions are SUPER sensitive (freekishly so). The simon says code usese +a delay and check process called debouncing to fix this. +////////////////////////////////////////////////// + */ @@ -19,7 +32,6 @@ int button_state; // This variable will be used to "store" the state of the b /// By sending these HIGH/LOW we can create a sound from the buzzer. int buzzer_1 = 4; int buzzer_2 = 7; - void setup() { pinMode(ledPin, OUTPUT); @@ -37,6 +49,7 @@ void setup() { void loop() { int button_state = digitalRead(buttonPin); + if(button_state == 1){ @@ -51,7 +64,6 @@ void loop() } - ////////////////////////////////////////////////////////////////////////////////////// void buzz(){ /// this function makes the buzzer pin move and crease a sound. diff --git a/Firmware/SIMON_4_MrRoboto/SIMON_4_MrRoboto.ino b/Firmware/SIMON_4_MrRoboto/SIMON_4_MrRoboto.ino new file mode 100644 index 0000000..89b51c8 --- /dev/null +++ b/Firmware/SIMON_4_MrRoboto/SIMON_4_MrRoboto.ino @@ -0,0 +1,95 @@ +/* +Simon Experiments #4 +Mr Roboto +Prof Mike Soltys +University of Colorado +01/15/2014 + +This example code is in the public domain. + +////////////////////////////////////////////////// +DESCRIPTION +Pressing the buttion will play the song Mr Roboto + +Note: these buttions are SUPER sensitive (freekishly so). The simon says code usese +a delay and check process called debouncing to fix this. +////////////////////////////////////////////////// + +*/ + + + +int ledPin = 3; // LEDs are on pins 3,5,10 and 13. +int buttonPin = 2; // BUTTONS are on pins 2,6,9 and 12. +int button_state; // This variable will be used to "store" the state of the button. + +/// These next two definitions are setting up the buzzer pins. +/// By sending these HIGH/LOW we can create a sound from the buzzer. +int buzzer_1 = 4; +int buzzer_2 = 7; + +/* Here are some variables we'll use to make a little jingle. + First we'll define frequencies of a few notes to use in the jingle */ +const int NOTE_F4 = 349; // F4 (F above middle c) +const int NOTE_DS4 = 311; // D-sharp 4 +const int NOTE_REST = 0; // Rest, no tone +const int jingleLength = 12; // This is the length of the jingle - 12 notes +/* This array contains the note played, in order */ +const int jingleNote[jingleLength] = { + NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_DS4, NOTE_REST, + NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_DS4}; +/* jingleDuration contains the length of each note played + 8 = 1/8 note, 4 = 1/4 note, 32 = 1/32 note, etc.*/ +const int jingleDuration[jingleLength] = { + 8, 8, 8, 8, 8, 4, 32,// do-mo-ar-i-ga-to-(rest) + 4, 4, 8, 8, 4 }; // mis-ter-ro-bot-o +const int jingleBPM = 60; // Jingle beats-per-minute = 60 bpm + +void setup() { + pinMode(ledPin, OUTPUT); + + digitalWrite(buttonPin, HIGH); + pinMode(buttonPin, INPUT); + + pinMode(buzzer_1, OUTPUT); + pinMode(buzzer_2, OUTPUT); + digitalWrite(buzzer_1, LOW); // buzzer_1 will toggle HIGH/LOW to create the sound - see buzz() function below. + digitalWrite(buzzer_2, LOW); // buzzer_2 will toggle as well (to create more volume). +} + + +void loop() +{ + int button_state = digitalRead(buttonPin); + + if(button_state == 1){ + + 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(); + + } + +} + +////////////////////////////////////////////////////////////////////////////////////// +void buzz(){ +for (int i=0; i