Offers a single master dimmer control for chosen R G B (and W) channels.
Suitable for controlling Neo-pixels or Sonoff B1 Lamps, set neo=1 or sonoff=1 as required, and the other=0.
Optional Title display, useful for distinguishing between multiple lamps.
Choice of 4 selectable rotary knob styles - upload file knob-full.js from bottom of this page to / of device. Optional Soft start brighten-up feature (easier on the eyes than sudden switch-ons).
Optional Auto save changed settings to file after timeout delay, for subsequent re-loading at next startup.
Uses embedded defaults when first run, which includes Autosave=0 (off), so changes will not be saved to file.
If Settingsfile is non-blank, and Autosave=1, the last used settings will automatically be saved to file after the 'delay' timeout, then reloaded again at startup to over-ride the embedded defaults. To always start with the same user defaults, set Autosave Off and manually save the required startup settings.
Basic:
'Rotary RGB Master Dimmer for NeoPixels or Sonoff B1 Lamps - Electroguard - Developed on Annex 1,41 beta 2
title$="Rotary Master Dimmer" 'title to be displayed if tc=1 sonoff=0 'set=1 if using a Sonoff B1 Lamp neo=1 'set=1 if using neo-pixels value=000 'initial master dial startup value softstart=1 'slow brighten up enabled=1 ssd=800 'softstart speed - ms delay between steps settingsfile$="/settings.ini" 'set="" if not wishing to read previous settings from file autosave=0 'autosave=1 to save changed settings to file after 'delay' delay=2000 'autosave delay before saving new settings to file knobstyle=3 'rotary knob style (1 to 4) r=0:g=0:b=0:cw=0:ww=0 'default start values of LED channels (cw=cold white, ww=warm white) rc=0:gc=0:bc=0:cwc=0:wwc=1 'default LED channels enabled=1 to be controlled by master dial tc=1:sc=1 'tc=1 to display title, sc=1 to show options if neo=1 then pixels = 12 'declare how many pixels to be addressed (12 for this example) neo.setup pixels 'initalise for declared number of pixels neo.strip 0, pixels-1 ,r,g,b 'turn all pixels off endif if sonoff=1 then sonoffb1.init 'initialise Sonoff B1 Lamp sonoffb1.rgb r,g,b 'display default RGB values sonoffb1.white cw,ww 'display default white values endif jsexternal "/knob-full.js" 'defaults to simple slider if the specified file is not available if settingsfile$ <> "" then gosub load 'comment out this line if you don't want to load saved settings if softstart=1 then gosub softstart onhtmlchange change 'subroutine branch to action controller changes gosub screen 'send screen output to browser wait load: if FILE.EXISTS(settingsfile$)=0 then return settings$ = FILE.READ$(settingsfile$) onerror ignore command settings$ onerror abort return save: settings$=|title$="|+title$+|":value=|+str$(knoboutput)+":softstart="+str$(softstart)+":ssd="+str$(ssd) settings$=settings$+":autosave="+str$(autosave)+":delay="+str$(delay)+":knobstyle="+str$(knobstyle) settings$=settings$+":rc="+str$(rc)+":gc="+str$(gc)+":bc="+str$(bc) settings$=settings$+":cwc="+str$(cwc)+":wwc="+str$(wwc)+":tc="+str$(tc)+":sc="+str$(sc) if sonoff=1 then settings$=settings$+":cw="+str$(cw)+":ww="+str$(ww) 'wlog settings$ FILE.SAVE settingsfile$,settings$ timer0 0 return screen: cls a$="" a$=a$+|<br>| a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 80%'>| if tc=1 then a$=a$+|<font color="teal">|+title$+|</font><br>| else a$=a$+"<br>" a$=a$+|<br>| a$=a$+|</div>| a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;'>| a$=a$+|<input class="preset|+str$(knobstyle)+|" data-var="knoboutput " value='|+str$(value)+|' type="range" min="0" max="255" | a$=a$+|data-width="250"data-height="250" data-angleOffset="220" data-angleRange="280" onchange='cmdChange(event)'>| a$=a$+|</div>| a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 100%'>| if sc=0 then ocol$="darkgrey" else ocol$="#404040" a$=a$+checkbox$(sc)+|<font color="|+ocol$+|">|+" Show Options"+|</font><br><br>| a$=a$+|</div>| if sc=1 then a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 80%'>| m$=|<input type="radio" data-var="knobstyle" name="gender" onchange="cmdChange(event)" | for c=1 to 4 a$=a$+m$ if c=knobstyle then a$=a$+| checked=1 | a$=a$+| value="|+str$(c)+| " > | next c a$=a$+|<br>| a$=a$+|</div>| a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 70%'>|+"Knob style" +|</div>| a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 100%'>| if sonoff=1 then a$=a$+checkbox$(cwc,"cwc")+|<font color="#000040">|+" Cold white"+|</font><br>| a$=a$+checkbox$(wwc,"wwc")+|<font color="#400000">|+" Warm white"+|</font><br>| endif a$=a$+checkbox$(rc,"rc")+|<font color="red">|+" Red"+|</font><br>| a$=a$+checkbox$(gc,"gc")+|<font color="green">|+" Green"+|</font><br>| a$=a$+checkbox$(bc,"bc")+|<font color="blue">|+" Blue"+|</font><br><br>| a$=a$+checkbox$(tc)+|<font color="teal">|+" Show Title"+|</font><br>| if softstart=0 then scol$="darkgrey" else scol$="#404040" a$=a$+checkbox$(softstart,"sc")+|<font color="|+scol$+|">|+" Soft start" a$=a$+" Fast "+slider$(ssd,9,999,"ss")+|<font color="|+scol$+|">|+" Slow<br>" +|</font>| a$=a$+cssid$("ss","width:40;height:5;") if autosave=0 then acol$="darkgrey" else acol$="#404040" a$=a$+checkbox$(autosave,"ac")+|<font color="|+acol$+|">|+" Auto save <br><br>" a$=a$+|</div>| a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 80%'>| a$=a$+ button$("Save",save) a$=a$+|<br>| a$=a$+|</div>| endif html a$ jscall "set_knobs();" return change: cmd$="value=V" cmd$=replace$(cmd$,"V","knoboutput") wlog cmd$ command cmd$ if sonoff=1 then cmd$="sonoffb1.rgb R,G,B" endif if neo=1 then cmd$="neo.strip 0,pixels-1,R,G,B" if rc=1 then cmd$=replace$(cmd$,"R","knoboutput") if gc=1 then cmd$=replace$(cmd$,"G","knoboutput") if bc=1 then cmd$=replace$(cmd$,"B","knoboutput") command cmd$ pause 10 if sonoff=1 then cmd$="sonoffb1.white cw,ww" if cwc=1 then cmd$=replace$(cmd$,"cw","knoboutput") if wwc=1 then cmd$=replace$(cmd$,"ww","knoboutput") command cmd$ endif if (HtmlEventVar$="sc") or (HtmlEventVar$="tc") or (HtmlEventVar$="softstart") or (HtmlEventVar$="autosave") then gosub screen if (HtmlEventVar$="knobstyle") then gosub screen if autosave=1 then timer0 delay,save HtmlEventVar$="" return softstart: for c=1 to value if sonoff=1 then cmd$="sonoffb1.rgb R,G,B" if neo=1 then cmd$="neo.strip 0, pixels-1,R,G,B" if rc=1 then cmd$=replace$(cmd$,"R",str$(c)) if gc=1 then cmd$=replace$(cmd$,"G",str$(c)) if bc=1 then cmd$=replace$(cmd$,"B",str$(c)) command cmd$ if sonoff=1 then cmd$="sonoffb1.white cw,ww" if cwc=1 then cmd$=replace$(cmd$,"cw",str$(c)) if wwc=1 then cmd$=replace$(cmd$,"ww",str$(c)) command cmd$ endif next c pause ssd return end '-----------end------------ |