Crack-the-code is a fairly simple arduino game you can show people, and let them play. The Game is similar to the game Mastermind in that you enter a code and then you get feedback getting you every turn a bit closer to cracking the code. This project is made with the goal of entertaining.
In this instructable I will show the exact staps needed to create the game.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Parts and Materials
3x Potentiometer 10 kilo-ohm, lineair with a 6mm diameter
3x Cover for 6mm Potentiometer
1x Red 1cm led
1x Green 1cm led
3x Yellow/orange 4mm led
1x Arduino UNO
1x Set of breadboard cables
5x 220 ohm resistor
Step 2: The Circuit
Connecting everything is quite simple, you only really have to pay attention to the resistors for the button and for the leds. Besides that the Potentio's are color coded, The first one is Black, second is green and the last potentio is blue. These colors will be referred to in the code.
The potentio meters are connected with the analog side, while the leds are connected though the digital side. The button gets elektricity from the analog side but its signal is digital.
Step 3: The Code
I have split the code into 3 sections.
The setup, the check and the leds part.
In the setup I create the code for the game, you can set any of the first three variables to a number between 1 and 9. I also define the 'Limit', 'buttonstate' and 'lastbuttonstate' variables.
Then in the void setup() you put in every pinMode and if it's an input or output. You will also need to set the begin for the serial to 9600.
In this piece of code I compare the buttonstate to it's previous state and then add a number to the Limit variable every time the buttonstate changes.
The leds part:
In this part we check the input from the potentio's and turn on the correct leds. If all of the numbers are wrong, the red led turns on, while if all numbers are correct the green led turns on. When any of the potentio's puts in a number that is in the code, the orange led corresponding that potentio, will turn on.
At the bottom of the code I have also set a limit of 20 tries before the red light starts flashing and the game stops.