Page 1 of 1

Dimming and a rotary-encoder

Posted: 21 Aug 2017, 20:49
by 19roland70
Is there anybody who has a example in rules how to dim a led with a Rotary encoder?

Re: Dimming and a rotary-encoder

Posted: 22 Aug 2017, 15:28
by quasar66
I'm using a slave arduino pro mini to read the encoder and publish it back via the I2C as a fake analog reading. This way I can read the encoder very fast. The code is similar with this viewtopic.php?f=2&t=3466 but with a rotary encoder instead of 6 digital pins.

From EspEasy I read analog4/5 (usually blocked by I2C but this is a fake reading), and I have a script that does PWM with %eventvalue% (as far as I remember, not at home right now). For a secondary remote Esp, I just publish the value to mqtt, so the first esp cand set the analog value.

Re: Dimming and a rotary-encoder

Posted: 22 Aug 2017, 19:24
by grovkillen
I have not tested this code myself but this is how I would do it.

LED on GPIO12 (D6).
Rotary Encoder with max value 100 and min value 0, the device named "rotary" and the value named "count".

Code: Select all

on rotary#count do
 pwm,12,[rotary#count]*10 //if you want the max value to be 1000
endon
You might want to change max value to "1000" and the rule to "pwm,12,[rotary#count]" for a slower increase in light. Or if you want the max light level to be lower than that you just change the max value accordingly. You'll just have to tinker until you get the result you want.

Re: Dimming and a rotary-encoder

Posted: 22 Aug 2017, 23:53
by 19roland70
grovkillen wrote: 22 Aug 2017, 19:24 I have not tested this code myself but this is how I would do it.

LED on GPIO12 (D6).
Rotary Encoder with max value 100 and min value 0, the device named "rotary" and the value named "count".

Code: Select all

on rotary#count do
 pwm,12,[rotary#count]*10 //if you want the max value to be 1000
endon
You might want to change max value to "1000" and the rule to "pwm,12,[rotary#count]" for a slower increase in light. Or if you want the max light level to be lower than that you just change the max value accordingly. You'll just have to tinker until you get the result you want.
How did you came on 1000?

Re: Dimming and a rotary-encoder

Posted: 23 Aug 2017, 06:50
by grovkillen
Since max value is set to 100 and I multiply each step with 10, the final sum will be 1000.

Re: Dimming and a rotary-encoder

Posted: 02 Sep 2017, 20:18
by happytm
I use following rules to control led on my connected pro-mini.you can replace command EXTPWM,13,[dummy#d1] with
PWM,13,[dummy#d1] to control local led on esp8266.It is also controlled by web browser with event command like:
http://<espeasyip>/control?cmd=event,dimmer1=0 (lowest level) or

http://<espeasyip>/control?cmd=event,dimmer1=1023 (highest level) or any value in between.
on ROTARY#counter do

TaskValueSet,6,1,[ROTARY#counter]*100 //scaling (i have my scaling in device setting for encoder as 1 to 10 to make roughly 10 steps dimmer)

EXTPWM,13,[dummy#d1] // pwm level value is taken from dummy sensor value
oled,1,2,[dummy#d1] // pwm level value is taken from dummy sensor value
endon


on dimmer1 do // when above command issued from browser
TaskValueSet 6,1,%eventvalue% // store pwm level value of 0 to 1023 from above command into dummy sensor
endon

on dummy#d1 do // when above value is stored in dummy sensor
EXTPWM,13,[dummy#d1] //pwm level value is taken from dummy sensor value
oled,1,2,[dummy#d1] // pwm level value is taken from dummy sensor value
endon
So now we havw control of led from encoder locally & remotely via web browser. and they are independent of each others pwm level value.

hope this helps.

Re: Dimming and a rotary-encoder

Posted: 09 Sep 2017, 12:01
by 19roland70
happytm wrote: 02 Sep 2017, 20:18 I use following rules to control led on my connected pro-mini.you can replace command EXTPWM,13,[dummy#d1] with
PWM,13,[dummy#d1] to control local led on esp8266.It is also controlled by web browser with event command like:
http://<espeasyip>/control?cmd=event,dimmer1=0 (lowest level) or

http://<espeasyip>/control?cmd=event,dimmer1=1023 (highest level) or any value in between.
on ROTARY#counter do

TaskValueSet,6,1,[ROTARY#counter]*100 //scaling (i have my scaling in device setting for encoder as 1 to 10 to make roughly 10 steps dimmer)

EXTPWM,13,[dummy#d1] // pwm level value is taken from dummy sensor value
oled,1,2,[dummy#d1] // pwm level value is taken from dummy sensor value
endon


on dimmer1 do // when above command issued from browser
TaskValueSet 6,1,%eventvalue% // store pwm level value of 0 to 1023 from above command into dummy sensor
endon

on dummy#d1 do // when above value is stored in dummy sensor
EXTPWM,13,[dummy#d1] //pwm level value is taken from dummy sensor value
oled,1,2,[dummy#d1] // pwm level value is taken from dummy sensor value
endon
So now we havw control of led from encoder locally & remotely via web browser. and they are independent of each others pwm level value.

hope this helps.
where must I place dummy#d1?
Is that anywhere in the "Devices" menu?

Re: Dimming and a rotary-encoder

Posted: 09 Sep 2017, 12:53
by grovkillen

Re: Dimming and a rotary-encoder

Posted: 13 Sep 2017, 00:30
by happytm
where must I place dummy#d1?
Is that anywhere in the "Devices" menu?
On devices page I have setup dummy sensor as task # 6 with four values with sensor name dummy and value names as d1,d2,d3 & d4.