Hello, I have 10 LEDs and I can make them light automatically from the first LED1 to LED10 , then it repeats again. But how do I make it light from LED1 to LED10 then directly LED10 to LED1 ( in the two lines of code below not by using the code twice…)
In case the 10 LED’s are from Pins 3 to 12, I already have the code :
for(int led=3; led<13 ;led++);
That code will not compile and once it compiles it will probably not do what you expect.
Please, when posting code here, use code tags and indent your code properly before posting; I suspect the use of a cellphone but that is not an excuse to not use code tags and not indent properly.
Also, your URGENT is not our urgent.
DO NOT CROSS-POST, CROSS-POSTING WASTES TIME.
I already have the code :
The code is not complete.
setup() function is missing completely.
And you only switch pins to HIGH in your code, never any pin to LOW again.
When setting an INPUT (default) pin to HIGH, this activates the internal pull-up resistor only, a connected LED at this pin will just glow very dimly, but not light up brightly.
What do you want? Explain in simple words?
Do you want some moving light, only one LED lighting at a time, running from left to right and from right to left? Something like the “Larson scanner” effect, as used in film and TV series “Knight Rider” some decades ago)?
But how do I make it light from LED1 to LED10 then directly LED10 to LED1 ( in the two lines of code below not by using the code twice...)
You could use two arrays, with pin numbers in one and pin states in the other. Put 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3 in one and 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 in the other.
Then, in the single for loop from 0 to 19, write the state to the matching pin.
Wonder how urgent this was?