variable delay time with rotary encoder

Hi there,
I would need a code that i can use to change the delay time from 5ms up to 10000ms using a rotary encoder with switch. So i can change the delay, and then set the value by pressing the switch.
And then the led for example would be able to blink with the new set delay time.
Any thoughts on this, Seen any axample of this?
Best regards

use a pot instead of the encoder? then

int dly=map(analogRead(Ax),0,1023,5,10000);

With an encoder: (much more code)
attach an interrupt (pin 2 or 3 on UNO) to one encoder output.
When interrupt i triggered:
{ // this routine is run
read the other encoder output.
if this is high → increase delay a little, else decrease it.
if new delay>10000 → set it 10000
if new delay<5 → set it to 5
// the delay variable must be declared volatile

I think the main problem is the wide range to be covered.
Somewhere I saw a code which uses a kind of acceleration - means the faster you turn the decoder the bigger the bigger the numbers jump per click.

Another way is to select digit by digit on a display, first select the "ones", turn the wheel until your desired digit is visible, then confirm with push button, then select the "tens" etc.

Good luck

Yes i saw something like that to somwhere. I was having the same thoughts as you. Mabey using an oled or something like that.

The reason for wanting to use encoder instead of pot, is that i find it more reliable to get a fixed value

This blog post has most of what you are looking for Relay Timer with LED Display – Arduino++

In terms of making the rotary encoder responsive to speed, I am using a technique in a current project that works well for me (I also with a large range to cover - 1Hz to 10Mhz). My MD_REncoder library can return a 'speed' indication for how fast the encoder is being turned. This ranges from 0 for slow turning to 50 or more for very fast turning. I then use the tens digit (speed/10) as the increment for the display by calculating the step size as 10^(speed/10). This provides a logarithmic increment step size, dependent on how fast the encoder is being turned. For slow turns this means increment of 1 (10^0) and for fast turns could be up to 10,000 (10^4). Allows precision if you need it but also covers large number spans when required.

Of course the base does not have to be 10. You can use 5, 3, 2, or bigger than 10, depending on how 'amplified' you want the steps to be. The divisor for the speed can also be something other than 10 to give you a different index value. Pick numbers that give you the kind of response you are looking for.

This sounds nothing short from genius :slight_smile: I am going to work from this as a base. Thank you. Though i have run in to a bit of a problem. I have the librarys loaded. but i still get this message.

Arduino:1.6.7 (Windows 10), Kort:“Arduino Nano, ATmega328”

WARNING: Category ‘Sensor Control’ in library MD_REncoder is not valid. Setting to ‘Uncategorized’
C:\Users\david\Documents\Arduino\libraries\MD_REncoder\src\MD_REncoder.cpp:26:23: fatal error: MD_Parola.h: No such file or directory

#include <MD_Parola.h>


compilation terminated.

Any ideas of what the problem might bee?

Hmm. That stuff was definitely not in my libraries but was in the download from the site.

I have corrected the problem by uploading to the libraries site again - please try and download again. Thanks for letting me know.