The ultimate memory game
Placed onTo begin...
To check the wiring of this project I wrote a little test code. When you press a button, the corresponding light would light up
testcode
The program
To start, we need to define all the pins, this way we can give the pins a name and don't have to use a pin number each time. Next, we need to set which pins are input and output. Since we opted for a 'grounded' or 'pullup' button, we'll include this info as well. Finally, we'll also add our variable for the buttons that we need.
random number
To grab random LEDs we use a random number generator. The Arduino has a random number generator built in, so with a bit of code we can make 3 LEDs light up randomly. To do this we need to add a new variable to our 'define place' (from above). We call this 'randNumber'. Then we put the code at our 'setup place' randomSeed(analogRead(0));. To then get a random number we need the code randNumber = random(4); to use. The randNumber is our variable, and the 4 stands for any number between 0 and 4.
This is what our code looks like now: