using potentiometer to set led blinking rate

cadej

New Member
Hi all, I need help with my PICAXE 14m2 flashing flower project. More precisely, the problem is in the setting blinking rate. My first idea was to predefine speeds and switching by pushbutton between them, but then I have got idea to use the potentiometer, but I do not know how to do it with a potentiometer.

A simple piece of code that I use (in the final version will be just more diodes)

start: high B.0
pause?? ; set by the potentiometer
low B.0
high B.1
pause?? ; set by the potentiometer
low B.1
pause?? ; set by the potentiometer
goto start

I'm an amateur, so please do not pester me if it's something simple and for my English, because it is not my native language. Thank you for your time and help.
 

Hemi345

Senior Member
Try this:

Code:
symbol potvalue = B.5 ;leg the potentiometer is connected to
symbol pausetime = w0 ;time for pause command 0-1023

start: 
readadc10 potvalue, pausetime ;read the value from the potentiometer (potvalue) and store it in pausetime
high B.0 
pause pausetime
low B.0 
high B.1 
pause pausetime ; set by the potentiometer 
low B.1 
goto start
 

cadej

New Member
Oh, as I see it, it's really easy, but I did not invent it as well. I will see, if it works, thank you very much.
 

erco

Senior Member
Dobrý den cadej and welcome to the forums & Picaxe family. As you saw, people are eager to help here, so don't hesitate to ask questions.

Na shledanou.
 

JBrookes

Member
But with pots, noise can be a big problem. So if you see unpredictable or variable results in the debug window, that's likely noise coming off the pot wiper.
I am told high-end pots are better, but no experience with...
 

Svejk

Senior Member
For a LED blinking noise isn't that much of an issue. An easy way to deal with it is to use say the four most significant bits from then readadc value and the multiply that with some value, ie (building on Hemi's code):

start:
readadc10 potvalue, pausetime ;read the value from the potentiometer (potvalue) and store it in pausetime
pausetime = pausetime /16
pausetime = pausetime * 20 ' or a value to suit application

high B.0
pause pausetime
etc
 
Top