Update frequency detection script

Michael Ingraham 2019-08-01 12:10:40 -04:00
parent d573736974
commit 578f7b6d1f
1 changed files with 137 additions and 53 deletions

@ -6,7 +6,7 @@
- [LED Bar Display with WS2812 LED Chain](#LED-Bar-Display-with-WS2812-LED-Chain) - [LED Bar Display with WS2812 LED Chain](#LED-Bar-Display-with-WS2812-LED-Chain)
- [Multiple IR Receiver Synchronization](#Multiple-IR-Receiver-Synchronization) - [Multiple IR Receiver Synchronization](#Multiple-IR-Receiver-Synchronization)
- [Fast Polling](#Fast-Polling) - [Fast Polling](#Fast-Polling)
- [Switching By Recognizing Mains Power Frequency](#Switching-By-Recognizing-Mains-Power-Frequency) - [Switching and Dimming By Recognizing Mains Power Frequency](#Switching-and-Dimming-By-Recognizing-Mains-Power-Frequency)
[Back To Top](#top) [Back To Top](#top)
@ -808,77 +808,161 @@ endif
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
#### Switching By Recognizing Mains Power Frequency #### Switching and Dimming By Recognizing Mains Power Frequency
Switching in Tasmota is usually done by High/Low (+3.3V/GND) changes on a GPIO. Here, however, this is achieved by a pulse frequency when connected to the GPIO, and these pulses are captured by `Counter1` in Tasmota.
![pushbutton-input](https://user-images.githubusercontent.com/36734573/61955930-5d90e480-afbc-11e9-8d7e-00ac526874d3.png)
- When the **light is OFF** and there is a **short period** of pulses **->** then turn the light **ON** at the previous dimmer level.
- When the **light is ON** and there is a **short period** of pulses **->** then turn the light **OFF**.
- When there is a longer period of pulses (i.e., **HOLD**) **->** toggle dimming direction and then adjust the brightness level as long as the button is pressed or until the limits are reached.
[#6085 (comment)](../issues/6085#issuecomment-512353010) [#6085 (comment)](../issues/6085#issuecomment-512353010)
In the Data Section >D at the beginning of the Script the following initialization variables may be changed:
- dim multiplier - 0..2.55 set the dimming increment value
- dim lower limit - range for the dimmer value for push-button operation (set according to your bulb); min 0
- dim upper limit - range for the dimmer value for push-button operation (set according to your bulb); max 100
- start dim level - initial dimmer level after power-up or restart; max 100
>**>D** >**>D**
sw1=0 sw=0
sw2=0 tmp=0
cnt1=0 cnt=0
cnt2=0 tmr=0
timer1=0 hold=0
timer2=0 powert=0
toggle1=0 slider=0
toggle2=0 dim=""
shortprl=2 ;short press lo limit
shortpru=10;short press up limit
dimdir=0 ;dim direction 0/1
dimstp=2 ;dim step/speed 1 to 5
dimmlp=2.2 ;dim multiplier
dimll=15 ;dim lower limit
dimul=95 ;dim upper limit
dimval=70 ;start dim level
>**>B** >**>B**
=>print "WiFi 2-Gang Switch Script" =>print "WiFi-Dimmer-Script-v0.2"
=>Counter1 0
=>Baudrate 9600
; boot sequence
=#senddim(dimval)
delay(1000)
=#senddim(0)
>**>F** >**>F**
; Counter1/2 and Relay1/2 configured in template cnt=pc[1]
cnt1=pc[1] if chg[cnt]>0
cnt2=pc[2] ; sw pressed
then sw=1
else sw=0
; sw not pressed
endif
> >
>if chg[cnt1]>0 >; 100ms timer
tmr+=1
>
>
>; short press
if sw==0
and tmr>shortprl
and tmr<shortpru
then then
; counter1 has changed, switch is on powert^=1
sw1=1 >
>; change light on/off
if powert==1
then
=#senddim(dimval)
else else
; no change switch is off =#senddim(0)
sw1=0 endif
endif endif
> >
>if chg[cnt2]>0 >
>; long press
if sw>0
then then
; counter2 has changed, switch is on if hold==0
sw2=1 then
>
>; change dim direction
dimdir^=1
endif
if tmr>shortpru
then
hold=1
if powert>0
>
>; dim when on & hold
then
if dimdir>0
then
>
>; increase dim level
dimval+=dimstp
if dimval>dimul
then
>
>; upper limit
dimval=dimul
endif
=#senddim(dimval)
else else
; no change switch is off
sw2=0
endif
> >
>; 100 ms timer >; decrease dim level
timer1+=1 dimval-=dimstp
timer2+=1 if dimval<dimll
>
>if sw1==0
and timer1>2
and timer1<30
then then
;=>print short press1 >
toggle1^=1 >; lower limit
=>Power1 %toggle1% dimval=dimll
endif
=#senddim(dimval)
endif
endif
endif
else
tmr=0
hold=0
endif
>**>E**
slider=Dimmer
>
>; slider change
if chg[slider]>0
then
>
>; dim according slider
if slider>0
then
dimval=slider
=#senddim(dimval)
else
powert=0
=#senddim(0)
endif
endif endif
> >
>if sw1==0 >if pwr[1]==1
; on/off webui
then then
timer1=0 powert=1
endif =#senddim(dimval)
> else
>if sw2==0 powert=0
and timer2>2 =#senddim(0)
and timer2<30
then
;=>print short press2
toggle2^=1
=>Power2 %toggle2%
endif
>
>if sw2==0
then
timer2=0
endif endif
>; subroutine dim
#senddim(tmp)
dim="FF55"+hn(tmp*dimmlp)+"05DC0A"
=>SerialSend5 %dim%
=>Dimmer %tmp%
\#
[Back To Top](#top) [Back To Top](#top)
------------------------------------------------------------------------------ ------------------------------------------------------------------------------