Just to clarify, I'm new with the Arduino programming... I'm still studying, trying to learn and I'm trying to control a WS2811 Led strip with 1 push button. The idea is to press once the button to switch the Leds on, starting from led 0 to the last one (creating a chasing effect) and then pressing again the same button I would like all the Leds to go off from the last to led 0 (opposite chasing effect).
Could anyone please help me.
Attached is my hardware connection and my software configuration (which i tried to modify from a library.
If clockwise and button pressed
Chase counterclockwise
If Counterclockwise and button pressed
Chase clockwise.
i.e. You'll need a variable to keep track of direction. That can be a type bool (1 or 0).
You might need a little delay/debouncing after the button press is detected so it doesn't get mixed up from button bounce, or if you hold the button too long.
An interrupt would be ideal because you wouldn't have to wait for the program to loop-around and read the button... But you can leave that for later, if you want to do it at all.
A toggle switch or an on/off pushbutton would simplify things. Then the switch is always telling it which way to go.
Do you have the code to reverse the chase? That might be tricky (depending on how the "forward" chase works. The data always goes through all of the LEDs in series. So if you want to chase backwards you have to keep track of the state of all the LEDs and re-write all of the LEDs. The library might do that, even if you are chasing forward so it may not even be an issue.
P.S. YOUR BUTTON WIRING IS WRONG... You need a pull-up or pull-down resistor. The resistor is wired to pull the input low and the button is wired between the Arduino input and 5V. When the button is pressed it "overpowers" the resistor forcing the input high. (As a "side effect" current flows through the resistor.) when the button is pressed.
Or there is a built-in pull-up resistor that you can enableso you don't have to add a resistor at all. I don't have a handy schematic, but the button is wired between the input and ground so when the button is pressed the input is pulled-low. (Then you usually need to reverse your software logic to recognize a low as a button-press.)