Go Down

Topic: Switch On Multiple LEDs with Single Switch (Read 559 times) previous topic - next topic

larryd

#15
May 14, 2017, 08:03 am Last Edit: May 14, 2017, 08:04 am by LarryD
Wire your LEDs as in the schematic below:




.
No technical PMs.
The last thing you did is where you should start looking.

larryd

"And If you can please tell me the logic behind this code."

What do you not understand?


.
No technical PMs.
The last thing you did is where you should start looking.

hashan22

i understand  the code... But I want  to know how you think.. The logic you build on your mind

larryd

#18
May 14, 2017, 07:28 pm Last Edit: May 14, 2017, 07:38 pm by LarryD
Always write your sketches so they are neat and easy to follow.

pushButton = 2;   use names that mean something to you

Your goal should be to have code that can be understood at some time in the future.

The only thing I would add to the code are comments which I purposely left out of this sketch.
const byte pushButton = 2; //pushed = LOW    tells you the switch is wired between GND and the pin.

Write your software so it can be changed to allow for expansion.
const byte leds[] = {3, 4, 5};    >>>>------>    const byte leds[] = {3, 4, 5, 6, 7, 8, 9}

Avoid hard coding, let the compiler do the work for you.
use: sizeof(leds)  instead of   3

Always put braces on separate lines by themself.
{
}

One line for each line of code.

Use arrays if possible.
leds[] = {3,4,5};

Use the smallest 'type' as you can.
byte counter;      instead of      int counter

Use 'const' for variables that do not change.
const byte counter

"i understand  the code..."
How would you change the code to get a pattern on the LEDs as below?
000, 001, 011, 111, 011, 001, 000, 001 etc.


.
No technical PMs.
The last thing you did is where you should start looking.

larryd

What is the quickest way to scare off an OP.

Answer:   >>       Ask them a question.     <<
No technical PMs.
The last thing you did is where you should start looking.

ledcorner

#20
May 17, 2017, 09:13 am Last Edit: May 17, 2017, 10:29 am by ledcorner
Hi,

Did you finish working on multiple LEDs? Tridonic LED drivers are good for LEDs or use LED controllers
LED lighting companies in Dubai

Go Up