Change Direction of Blinking Lights in the Opposite Direction

Hello, I am looking to change the direction of my LED's blinking when a button is pressed on. I have the LEDs blinking from port 5 to port 6 to port 7. I want to reverse the direction of the LEDs blinking when a button is pushed. So when the LEDs go from port 7 to port 6 to port 5.

Any input would be much appreciated.

void setup() {
// initialize digital pin 5, 6, and 7 as an output.
pinMode(5, OUTPUT); // initalize pin 5 for output
pinMode(6, OUTPUT); // initalize pin 6 for output
pinMode(7, OUTPUT); // initalize pin 7 for output
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(5, LOW); // turns LED on
delay(250); // delay 250ms
digitalWrite(5, HIGH); // turns LED off
delay(250); // delay 250ms
digitalWrite(6, LOW); // turns LED on
delay(250); // delay 250ms
digitalWrite(6, HIGH); // turns LED off
delay(250); // delay 250ms
digitalWrite(7, LOW); // turns LED on
delay(250); // delay 250ms
digitalWrite(7, HIGH); // turns LED off
delay(250); // delay 250ms
}

Hi newbee,

you are welcome in the forum.
I'm a guy who likes to help making people able to help themselves. I have looked up yours posts.
From your posts I got the impression your will to learn is pretty limited. If my impression is wrong I aplogise.

The best way to give a other impression is to start asking concrete questions.
Concrete questions ask for a specific detail. If you are unable to do that you can step back to become a bit more general like;

"Where can I find information about programming with buttons?"

My answer
Whenever you use additional hardware even such simple things like a LED or a button you have to have a basic knowledge about electronics too.

OK here it is:
how to connect and program switches / buttons

Another example for a concrete question:

How would I program to make my 3 LEDs light up in reversed order?

My answer: You connected your LEDs to IP-pin
5
6
7

How would you write down these three numbers on a sheet of paper in reversed order?

in a program this follows the same principle. So give it a try.
If your modified code does not compile or does compile but the LEDs do something different
just post your complete sketch and describe what is happening. For such questions you will get help

Your sentence "Any input would be much appreciated." is a diplomatic hidden way of saying:

"I'm too lazy to learn it. Can somebody post a completed sketch so I have no work with my assigment"

In general this tutorial is easy to read and a good mixture between imprtant concepts you have to know
and explaining commands to get you going.

Arduino Programming Course

best regards Stefan

StefanL38:
Hi newbee,

you are welcome in the forum.
I'm a guy who likes to help making people able to help themselves. I have looked up yours posts.
From your posts I got the impression your will to learn is pretty limited. If my impression is wrong I aplogise.

The best way to give a other impression is to start asking concrete questions.
Concrete questions ask for a specific detail. If you are unable to do that you can step back to become a bit more general like;

"Where can I find information about programming with buttons?"

My answer
Whenever you use additional hardware even such simple things like a LED or a button you have to have a basic knowledge about electronics too.

OK here it is:
how to connect and program switches / buttons

Another example for a concrete question:

How would I program to make my 3 LEDs light up in reversed order?

My answer: You connected your LEDs to IP-pin
5
6
7

How would you write down these three numbers on a sheet of paper in reversed order?

in a program this follows the same principle. So give it a try.
If your modified code does not compile or does compile but the LEDs do something different
just post your complete sketch and describe what is happening. For such questions you will get help

Your sentence "Any input would be much appreciated." is a diplomatic hidden way of saying:

"I'm too lazy to learn it. Can somebody post a completed sketch so I have no work with my assigment"

In general this tutorial is easy to read and a good mixture between imprtant concepts you have to know
and explaining commands to get you going.

Arduino Programming Course

best regards Stefan

This is possibly one of the best ever responses to a question I have seen in a long time. Karma added.

Did you try with what you already have there in loop() just written in reverse order, in the else part of an if?

So your pseudo-code would be:

if button is not pressed
  run what you already have
else (ie the button is pressed)
 run a chunk of code like you already have but written upside down

But there are problems with that due to the use of delay() so it would be better to look at a delay()-less, millis()-based approach

If you want to get really fancy, and have a nice scaleable solution to make it easy to change the number of leds, stick the pins* in an array, and use the button state to increment or decrement the array counter so it goes left or right.

port 5 to port 6 to port 7.

*They're not ports. A port is a specific collection of certain pins.