Potentio meter affects speed of led lights

hello

i need to make an arduino project where i put 5 led lights next to each other and that and that they go on and off in sequence (like knightriders car ) and i need to add a potentio meter to it that adjusts the speed of it for example if it is all the way left they change slow and if it is on the right they change super fast.

how do i do this ? (this may sound very easy but i just don't know)

Thanks in advance

Replace the constant in your call to delay with a value read from the potentiometer

(It would be useful if you posted your code)

1 Like

Just to check, you have it working up to the part where you need to add the potentiometer?

Somewhere in that code you must have some kind of timing taking place. So make that timing value a variable, read the pot and then you could perhaps map the pot's value to the minimum and maximum timings.

(BTW, it's one word, not potentio meter :wink: )

1 Like

Welcome to the forum

Have you looked at the Blink example in the IDE ? It will show you how to turn a single LED on and off

1 Like

Hello,
The problem is i dont have the code because i dont know any code for it.
I hope you can help me and give me some simple code so if i change my potentiometer its affects the speed of my led lights

Kind regards

I'm sure there are plenty of examples of Knightrider leds things around, why don't you search for those and get one working first. I think it's called a "Larson scanner" after the guy who invented it.

Once you have one working, then try to add the pot timing yourself and see how far you get.

1 Like

Do you have the code for the LED sequence? Of course it's been done before, and I've made something "similar" but the code depends on which pins the LEDs are connected to and the number of LEDs, etc. My particular version is too complicated to use as an example because it's sound activated (which requires more hardware and software), it's got more than 5 lights, and it's got "variations" such as a having variable number of LEDs on at one time... Sometimes one LED "bounces" back-and-forth, and sometimes two LEDs, etc. (and another variation that's not easy to describe in words).

If you don't have that code study the Blink Example.

Then make the delay time a variable instead of a constant 1000. For now, you can set the variable to 1000, but the point is to use the variable name instead of typing "1000". You can name it whatever you want... You can call it "Wait" or whatever you want. For example, *"Delay(Wait)"*instead of "Delay(1000)". Or, you can have different WaitOn and WaitOff variables if you want. And for now, you can initialize your variable(s) to 1000 in setup() before the code starts running loop().

Then add another LED and add some more similar code to blink the LEDs in sequence.

Then add the other 3 LEDs (or however many you want) and make them all sequence.

Then make add some more code to make it sequence both ways.

If you don't know how to hook-up a pot, look at the Analog Read Serial Example.

To begin with you can simply use the pot reading (0-1023) as your delay time.

Read the pot and update your delay variable at the beginning of the loop.

Or you can map() the 0-1023 pot reading to a delay range of your choice.

After you've got everything working (and after you understand what you're doing) you might want to re-write the code using the method in the Blink Without Delay example.

...You'll only be reading the pot once every time through the loop, so with delays it won't respond "instantly". Using millis() timers like Blink Without Delay makes the loop run faster and it can read the pot more frequently and your program will be more responsive to pot changes.

1 Like

Hello soaring_noob
It seems to be a school assigment, isn´t it?
When is the due date?

Have a nice day and enjoy coding in C++.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.