Dimming and a rotary-encoder

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
19roland70
New user
Posts: 7
Joined: 18 Mar 2017, 12:22

Dimming and a rotary-encoder

#1 Post by 19roland70 » 21 Aug 2017, 20:49

Is there anybody who has a example in rules how to dim a led with a Rotary encoder?

quasar66
New user
Posts: 6
Joined: 18 Aug 2017, 22:20

Re: Dimming and a rotary-encoder

#2 Post by quasar66 » 22 Aug 2017, 15:28

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.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Dimming and a rotary-encoder

#3 Post by grovkillen » 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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

19roland70
New user
Posts: 7
Joined: 18 Mar 2017, 12:22

Re: Dimming and a rotary-encoder

#4 Post by 19roland70 » 22 Aug 2017, 23:53

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?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Dimming and a rotary-encoder

#5 Post by grovkillen » 23 Aug 2017, 06:50

Since max value is set to 100 and I multiply each step with 10, the final sum will be 1000.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

happytm
Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

Re: Dimming and a rotary-encoder

#6 Post by happytm » 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.

19roland70
New user
Posts: 7
Joined: 18 Mar 2017, 12:22

Re: Dimming and a rotary-encoder

#7 Post by 19roland70 » 09 Sep 2017, 12:01

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?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Dimming and a rotary-encoder

#8 Post by grovkillen » 09 Sep 2017, 12:53

ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

happytm
Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

Re: Dimming and a rotary-encoder

#9 Post by happytm » 13 Sep 2017, 00:30

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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 25 guests