Light Scan + Button push

Hi all, here is my code:

int LED1Pin = 1;
int LED2Pin = 2;
int LED3Pin = 3;
int LED4Pin = 4;
int LED5Pin = 5;
const int LEDBUTTON = 12;
const int BUTTON = 7;
int VAL = 0;
int scan = 0;

void setup(void) {

pinMode(LED1Pin, OUTPUT);
pinMode(LED2Pin, OUTPUT);
pinMode(LED3Pin, OUTPUT);
pinMode(LED4Pin, OUTPUT);
pinMode(LED5Pin, OUTPUT);

void loop() {

/*VAL = digitalRead(BUTTON);
if (VAL == HIGH) {
digitalWrite(LEDBUTTON, HIGH);
  }else {
    digitalWrite(LEDBUTTON, LOW);
int scan = 0;
for (int scan = 1; scan <9; scan++){

  digitalWrite (LED1Pin, LOW);
  digitalWrite (LED2Pin, LOW);
  digitalWrite (LED3Pin, LOW);
  digitalWrite (LED4Pin, LOW);
  digitalWrite (LED5Pin, LOW);
  if (scan ==1) digitalWrite(LED1Pin, HIGH);
  if (scan ==2) digitalWrite(LED2Pin, HIGH);
  if (scan ==3) digitalWrite(LED3Pin, HIGH);
  if (scan ==4) digitalWrite(LED4Pin, HIGH);
  if (scan ==5) digitalWrite(LED5Pin, HIGH);
  if (scan ==6) digitalWrite(LED4Pin, HIGH);
  if (scan ==7) digitalWrite(LED3Pin, HIGH);
  if (scan ==8) digitalWrite(LED2Pin, HIGH);




I'm a real novice and trying to learn to code whilst also teaching my 9 year old how to do it and we're hitting some stumbling blocks.

Essentially we want there to be a number of lights (in this instance 5) that move in the order 1,2,3,4,5,4,3,2,1 and then when you press the button the code pauses, checks the number of the pin it is on and if it is #3 you gain a point which we will add an LED to. Each time you get it right the speed increases but as soon as you hit 1,2,4,5 the program will break and have a reset button to be tried again.

I was thinking I could use the serial monitor for importing the value of the light that is turned on (so I can see what is happening) and then some form of break, but I really am losing the will to live here, nothing seems to be working as I want.

Please, please Arduino gods, help me (and my daughter!)

First question before we dive into a solution, do you have LED's hooked up on a breadboard properly with a resistor on each positive lead from the LED and a proper ground?

You also need to understand the atmega328p pin map:

As you can see the above is for the chip itself. You are working with a chip on the UNO board so you want to reference this:

As you can see some of the pin numbers have other purposes. You want to start designing your project with the pin mapping first.

Try to work up a plan this will help you and your daughter a great deal to get a solid understanding. Work up something and think about redesigning your code and we will help you along.


Thanks for the quick reply, yeah I have it set up with a resistor to each positive lead and the whole thing going to ground on the Uno.

Did you take a look at the pin map I gave in my original post? This will help you create a proper sketch.