Introduction: Simon Says Game Made Using Evive (Arduino Powered Embedded Product)
How fun it will be first to make a DIY game and then play it woth your friends! So here we will make a game. Its called Simon Says. We have made this game using evive. The codes are developed in very simple fashion in Arduino IDE. The objective of the game is simple: there are five LEDs/bulbs and five corresponding switches. The bulbs light up in a random order generated everytime. You then have to press the buttons in the exact same order. If the sequence is correct, a 'correct' sequence of lights starts and you will progress to the next level. The current level number will be displayed on the TFT screen of evive. Otherwise, an 'incorrect' sequence lights up. A "Game Over" is displayed on the screen.
Step 1: Components Used
- (Optional) TFT screen (evive has inbuit TFT screen :P )
- male- male jumper cables
- Breadboard wires
- 5 LEDs
- 5 Push (Tactile) Buttons
- 5 Resistors 220 ohms each
- 5 Resistors 1 kilo-ohm each
Step 2: Making the Connections
First, we make the first bulb- pushbutton set.
- Place a pushbutton on the breadboard.
- Now, above the right side of the button, insert the positive terminal of the led (the longer one) and the negative terminal into the hole right to it. Now, ground the negative terminal through a 220 ohm resistor.
- Make the left side of the pushbutton positive.
- Now, connect the other side of the pushbutton to a digital pin of the evive (pin2).
- Also, ground this through a 1 kilo ohm resistor (pulling down the switch)
Now we just have to repeat the above process 4 more times. Connect these to pins 3,4,5 and 6. For more info you can see the circuit diagram.
Notice that at this point, any pushbutton you press will light up the corresponding bulb. Take care not to inter- connect two different bulb- pushbutton sets.
evive has inbuit 1.8" TFT screen with SPI interface. You can check the internal wiring diagram here.
Step 3: Coding the Game
We are using same pins i.e. 2, 3, 4, 5 and 6 as both input and output.
Initially, we declare all the pins connected to bulbs as OUTPUT. This will enable them to glow (for the showing of the sequence). After the showing of the sequence, the pins are declared as INPUT (for getting input from the pushbutton response)
The basic motive is to determine which button is being pressed. Since only one pushbutton will be pressed at a given time, it is fine to check if any of the input pins is HIGH in an 'or' statement. Then we can check which of the buttons was pressed individually.
The target sequence (shown initially) is generated by using the pseudo-random number generator of the Arduino IDE. After the input response is registered, it will be compared with the target sequence.
You can view and download the code at our git repository.
Step 4: Displaying Text on the Tft
evive uses ST7735 SPI 1.8" colored TFT screen and the library for this screen is available on adafruit. This is a hardware level library. You can download the library from github https://github.com/adafruit/Adafruit-ST7735-Library
Some examples are also included in the github repository above.
To display text, we basically need these three functions-
- setTextColor(textcolor, textbackgroundcolor)
- setCursor(x-coordinate, y-coordinate)
The screen is cleared by setBackgroundColor(backgroundcolor).
Step 5: Setting Different Levels
We have set some levels also, actually it has 10 levels. As you approach the next level the time delay for which the LED is on is reduced. In level 1 it is about 500 milliseconds, after level it get reduced by 50 milliseconds.
Step 6: Finally, Play the Game Made by YOU With Evive Using Arduino IDE
Participated in the