This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>D | |
sw=0 | |
tmp=0 | |
cnt=0 | |
tmr=0 | |
hold=0 | |
powert=0 | |
slider=0 | |
dim="" | |
shortprl=2 ;short press lo limit | |
shortpru=10;short press up limit | |
dimdir=0 ;dim direction 0/1 | |
dimmlp=2.2 ;dim multiplier 1..2.55 | |
dimstp=2 ;dim step/speed 1..5 | |
dimll=15 ;dim lower limit min. 0 | |
dimul=95 ;dim upper limit max. 100 | |
dimval=70 ;start dim level 0..100 | |
>B | |
=>print > WiFi-Dimmer-Script-v1.0 < | |
=>Counter1 0 | |
=>Baudrate 9600 | |
; boot sequence | |
=#senddim(dimval) | |
delay(1000) | |
=#senddim(0) | |
>F | |
cnt=pc[1] | |
if chg[cnt]>0 | |
; sw pressed | |
then sw=1 | |
else sw=0 | |
; sw not pressed | |
endif | |
; 100ms timer | |
tmr+=1 | |
; short press | |
if sw==0 | |
and tmr>shortprl | |
and tmr<shortpru | |
then | |
powert^=1 | |
; change light on/off | |
if powert==1 | |
then | |
=#senddim(dimval) | |
else | |
=#senddim(0) | |
endif | |
endif | |
; long press | |
if sw>0 | |
then | |
if hold==0 | |
then | |
; change dim direction | |
dimdir^=1 | |
endif | |
if tmr>shortpru | |
then | |
hold=1 | |
; if off powert correction | |
if powert==0 | |
then | |
powert=1 | |
endif | |
; dim when on & hold | |
if dimdir>0 | |
then | |
; increase dim level | |
dimval+=dimstp | |
if dimval>dimul | |
then | |
; upper limit change direction | |
dimdir^=1 | |
endif | |
=#senddim(dimval) | |
else | |
; decrease dim level | |
dimval-=dimstp | |
if dimval<dimll | |
then | |
; lower limit change direction | |
dimdir^=1 | |
endif | |
=#senddim(dimval) | |
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 | |
else | |
powert=0 | |
endif | |
endif | |
if pwr[1]==1 | |
; on/off webui | |
then | |
powert=1 | |
=#senddim(dimval) | |
else | |
powert=0 | |
=#senddim(0) | |
endif | |
; subroutine dim | |
#senddim(tmp) | |
dim="FF55"+hn(tmp*dimmlp)+"05DC0A" | |
=>SerialSend5 %dim% | |
=>Dimmer %tmp% | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment