The ultimate memory game

Placed on

To 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

First of all, we need to define all pins, this ensures that we can name the pins, and we don't have to use a pin number every time. Next we need to set which pins are input and output. Because we have opted for a 'grounded' or 'pullup' push button, we also add this. Finally, we also add our variable that we need for the buttons.

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:

Current Page 5. Programming (1) 1. Introduction 2. Buttons 3. The LEDs 4. The wiring 5. Programming (1) 6. Programming (2) 7. Programming (3) 8. A housing Posted by Student industrial sciences

Comments

Webwinkelkeur Kiyoh Trustpilot Opencircuit