Simon Says

Press the buttons according to the color of he LED Lights

COMPONENTS AND SUPPLIES

220 Ohm Resistor

4

LED

4

InventrKits HERO

The HERO is a derivative of “Arduino UNO R3 Reference design” we just changed up a few things to make it our own. If you’re curious about what goes into our HERO board we published the open-source hardware files on our GitHub.

1

Small Breadboard

1

Passive Buzzer Module

1

ABOUT THIS PROJECT

Simon says follow the light pattern using the corresponding buttons. The longer you play, the longer the pattern will be.

CODE

				
					
				
			

SCHEMATICS

Simon Says Diagram

COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *

const int led_red = 1; // Output pins for the LEDs const int led_blue = 2; const int led_yellow = 3; const int led_green = 4; const int buzzer = 5; // Output pin for the buzzer const int red_button = 9; // Input pins for the buttons const int blue_button = 10; const int yellow_button = 11; const int green_button = 12; // Pin 13 is special – didn’t work as planned long sequence[20]; // Array to hold sequence int count = 0; // Sequence counter long input = 5; // Button indicator int wait = 500; // Variable delay as sequence gets longer /* playtone function taken from Oomlout sample takes a tone variable that is half the period of desired frequency and a duration in milliseconds */ void playtone(int tone, int duration) { for (long i = 0; i < duration * 1000L; i += tone *2) { digitalWrite(buzzer, HIGH); delayMicroseconds(tone); digitalWrite(buzzer, LOW); delayMicroseconds(tone); } } /* functions to flash LEDs and play corresponding tones very simple - turn LED on, play tone for .5s, turn LED off */ void flash_red() { digitalWrite(led_red, HIGH); playtone(2273,wait); // low A digitalWrite(led_red, LOW); } void flash_blue() { digitalWrite(led_blue, HIGH); playtone(1700,wait); // D digitalWrite(led_blue, LOW); } void flash_yellow() { digitalWrite(led_yellow, HIGH); playtone(1275,wait); // G digitalWrite(led_yellow, LOW); } void flash_green() { digitalWrite(led_green, HIGH); playtone(1136,wait); // high A digitalWrite(led_green, LOW); } // a simple test function to flash all of the LEDs in turn void runtest() { flash_red(); flash_green(); flash_yellow(); flash_blue(); } /* a function to flash the LED corresponding to what is held in the sequence */ void squark(long led) { switch (led) { case 0: flash_red(); break; case 1: flash_green(); break; case 2: flash_yellow(); break; case 3: flash_blue(); break; } delay(50); } // function to congratulate winning sequence void congratulate() { digitalWrite(led_red, HIGH); // turn all LEDs on digitalWrite(led_green, HIGH); digitalWrite(led_yellow, HIGH); digitalWrite(led_blue, HIGH); playtone(1014,250); // play a jingle delay(25); playtone(1014,250); delay(25); playtone(1014,250); delay(25); playtone(956,500); delay(25); playtone(1014,250); delay(25); playtone(956,500); delay(2000); digitalWrite(led_red, LOW); // turn all LEDs off digitalWrite(led_green, LOW); digitalWrite(led_yellow, LOW); digitalWrite(led_blue, LOW); resetCount(); // reset sequence } // function to reset after winning or losing void resetCount() { count = 0; wait = 500; } // function to build and play the sequence void playSequence() { sequence[count] = random(4); // add a new value to sequence for (int i = 0; i < count; i++) { // loop for sequence length squark(sequence[i]); // flash/beep } wait = 500 - (count * 15); // vary delay count++; // increment sequence length } // function to read sequence from player void readSequence() { for (int i=1; i < count; i++) { // loop for sequence length while (input==5){ // wait until button pressed if (digitalRead(red_button) == LOW) { // Red button input = 0; } if (digitalRead(green_button) == LOW) { // Green button input = 1; } if (digitalRead(yellow_button) == LOW) { // Yellow button input = 2; } if (digitalRead(blue_button) == LOW) { // Blue button input = 3; } } if (sequence[i-1] == input) { // was it the right button? squark(input); // flash/buzz if (i == 20) { // check for correct sequence of 20 congratulate(); // congratulate the winner } } else { playtone(4545,1000); // low tone for fail squark(sequence[i-1]); // double flash for the right colour squark(sequence[i-1]); resetCount(); // reset sequence } input = 5; // reset input } } // standard sketch setup function void setup() { pinMode(led_red, OUTPUT); // configure LEDs and buzzer on outputs pinMode(led_green, OUTPUT); pinMode(led_yellow, OUTPUT); pinMode(led_blue, OUTPUT); pinMode(buzzer, OUTPUT); pinMode(red_button, INPUT); // configure buttons on inputs digitalWrite(red_button, HIGH);// turn on pullup resistors pinMode(green_button, INPUT); digitalWrite(green_button, HIGH); pinMode(yellow_button, INPUT); digitalWrite(yellow_button, HIGH); pinMode(blue_button, INPUT); digitalWrite(blue_button, HIGH); randomSeed(analogRead(5)); // random seed for sequence generation //runtest(); } // standard sketch loop function void loop() { playSequence(); // play the sequence readSequence(); // read the sequence delay(1000); // wait a sec }
PROJECT AUTHOR
Leave a comment
TEAM MEMBERS
Alexander Eschenauer

Circuit builder and Coder

ADDITIONAL CONTRIBUTORS
TABLE OF CONTENTS
Leave a comment
Share on whatsapp
Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on pinterest
Share on email

SIMILAR PROJECTS YOU MIGHT LIKE

I cascaded four SN74HC595 shift registers to control 32 LEDs on 4 registers using 3 wires. I am adding a I2C 20×4 LCD screen to display the register and led values. I might add a standard 16×2 LCD screen to show up it is done.
A simple light meter. It’s not calibrated to any meaningful scale, but the digital readout shows a higher number the brighter is the light falling on the photoresistor.