Dimming and a rotary-encoder
Moderators: grovkillen, Stuntteam, TD-er
-
- New user
- Posts: 7
- Joined: 18 Mar 2017, 12:22
Dimming and a rotary-encoder
Is there anybody who has a example in rules how to dim a led with a Rotary encoder?
Re: Dimming and a rotary-encoder
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.
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.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Dimming and a rotary-encoder
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".
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.
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
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

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



-
- New user
- Posts: 7
- Joined: 18 Mar 2017, 12:22
Re: Dimming and a rotary-encoder
How did you came on 1000?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".
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.Code: Select all
on rotary#count do pwm,12,[rotary#count]*10 //if you want the max value to be 1000 endon
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Dimming and a rotary-encoder
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

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



Re: Dimming and a rotary-encoder
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.
hope this helps.
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.
So now we havw control of led from encoder locally & remotely via web browser. and they are independent of each others pwm level value.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
hope this helps.
-
- New user
- Posts: 7
- Joined: 18 Mar 2017, 12:22
Re: Dimming and a rotary-encoder
where must I place dummy#d1?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.
So now we havw control of led from encoder locally & remotely via web browser. and they are independent of each others pwm level value.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
hope this helps.
Is that anywhere in the "Devices" menu?
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Dimming and a rotary-encoder
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

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



Re: Dimming and a rotary-encoder
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.where must I place dummy#d1?
Is that anywhere in the "Devices" menu?
Who is online
Users browsing this forum: No registered users and 21 guests