continuously rotation of LED

Hi guys :slight_smile: I have a problem on my program. The LED’s must rotate continuously but it STopS after 2 rotations. Whats wrong??? Thanks. :smiley:
Heres my code:

int timer = 100;
int ledPins = {
13,12,11, 10, 9, 8, 7, 6}; // an array of pin numbers to which LEDs are attached
int pinCount = 8; // the number of pins (i.e. the length of the array)
int buttonPin = 1;
int buttonPin1 = 4;
int buttonPin2 = 3;
int ledPin1 =12;
int ledPin2 =11;
int ledPin =13;
int buttonState = 0;
int buttonState1 = 0;
int buttonState2 = 0;
void setup() {
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin2, INPUT);
pinMode(ledPin2, OUTPUT);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}

void loop() {
// loop from the lowest pin to the highest:
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH ) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(timer);
digitalWrite(ledPin, LOW);
}
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 == HIGH ) {
// turn LED on:
digitalWrite(ledPin1, HIGH);
delay(timer);
digitalWrite(ledPin1, LOW);
}
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 == HIGH ) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
delay(timer);
digitalWrite(ledPin2, LOW);

for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);

}

// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin–) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}
}

Hi, Sharmane, please read
http://forum.arduino.cc/index.php/topic,148850.0.html
To help you post your code using # code tags.
You can go back into your post and edit it.

We would like to help, can you tell us what your sketch is supposed to do?

What are the inputs and outputs, and what are they supposed to do?

Tom...... :slight_smile:

Some questions

Why are the pin numbers for ledPin, ledPin1 and ledPin2 also in the ledPins array ?
How are the buttons wired ?
Do they have any pull down resistors ?
Why are you using ints for variables that could just as easily be bytes which would save space ?

TomGeorge:
Hi, Sharmane, please read
http://forum.arduino.cc/index.php/topic,148850.0.html
To help you post your code using # code tags.
You can go back into your post and edit it.

We would like to help, can you tell us what your sketch is supposed to do?

What are the inputs and outputs, and what are they supposed to do?

Tom...... :slight_smile:

Hi Tom, sorry I just thought that I dont need to post the schematic. :slight_smile:
anyway, i just posted it.

UKHeliBob:
Some questions

Why are the pin numbers for ledPin, ledPin1 and ledPin2 also in the ledPins array ?
How are the buttons wired ?
Do they have any pull down resistors ?
Why are you using ints for variables that could just as easily be bytes which would save space ?

hi Bob, :slight_smile:
I have 8 LEDS, First I need to press buttons 1,4,3 and Then LED's will ON and rotate.
My problem is it doesn't rotate continuously.
Yeah, ur right bytes would save more space. haha. I just dont feel using it.

You are missing or have miss placed a }
This has the effect of only running your "looping of LEDs" when buttonPin2 is high.

Here is a trick, click the cursor just after an opening { and the matching } will be shown outlines. This will allow you to see the scope of the code that is conditional after any if ststement.

Grumpy_Mike:
You are missing or have miss placed a }
This has the effect of only running your "looping of LEDs" when buttonPin2 is high.

Here is a trick, click the cursor just after an opening { and the matching } will be shown outlines. This will allow you to see the scope of the code that is conditional after any if ststement.

oops.. I copied the wrong code. I already modified it. thanks for the info. :slight_smile:

I already modified it.

I do wish that people would not modify code in posts because it makes a nonsense of comments about the original code, and you still have not put it in code tags as suggested.

Hi, Sharmane, looking at your circuit, you are using pins 0 and 1 for inputs, unfortunately they are used as programming pins and could be causing some of your problem.
You can use the analog pins as digital inputs instead.

Tom..... :slight_smile:

sharmane18:

Grumpy_Mike:
You are missing or have miss placed a }
This has the effect of only running your "looping of LEDs" when buttonPin2 is high.

Here is a trick, click the cursor just after an opening { and the matching } will be shown outlines. This will allow you to see the scope of the code that is conditional after any if ststement.

oops.. I copied the wrong code. I already modified it. thanks for the info. :slight_smile:

Well the code in that first post is still wrong in exactly the same way as I said before. You will only get the looping if you continue to hold button 2 down.

The way it works here is that if you change your code you post it again and post it properly in code tags.
Now we have been cutting you a lot of slack here but if you continue to ignore us things start to get a little frosty and no one wants that.

get a little frosty and no one wants that.

Unless you are at Dairy Queen. Then, a little Frosty is great. Of course, a big one is better... 8)