RGB Colour Wheel Controller for Neo-pixels or Sonoff B1 Lamps
Simple and intuitive control of RGB LED lighting.
Optional 'Autosave' changes to file for reloading at next startup.
Optional title to differentiate between multiple devices.
The script requires Annex 1,41 beta 5 or later, plus the appropriate .js files to be available.
Basic:
'RGB Colour Wheel for NeoPixels or Sonoff B1 Lamps - Electroguard - Developed on Annex 1,41 beta 5
title$="RGB Colour Wheel" 'title that will be displayed if not blank
sonoff=0 'set=1 if using a Sonoff B1 Lamp
neo=1 'set=1 if using neo-pixels, coonect data-in to gpio2
rgb$="a0a0a0" 'initial startup RRGGBB value, "0"=min Off, "ffffff"=max On
autosave=1 'set=1 to save last changed RGB values for reloading at next startup
if autosave=1 then 'note: will over-ride the embedded RGB value
delay=5000 'delay in ms before saving changed RGB values to file
filename$="/previous" 'change filename if wished, but prefix with /
onerror skip
if file.read$(filename$) <> "" then rgb$=file.read$(filename$)
endif
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,val("&h"+rgb$) 'display initial startup rgb$ value
endif
if sonoff=1 then
sonoffb1.init 'initialise Sonoff B1 Lamp
sonoffb1.white 0,0 'set white LEDs off sonoffb1.rgb val("&h"+rgb$) 'display initial startup rgb$ valuesendifonhtmlchange change 'subroutine branch to action browser screen changesjsexternal "/html_obj.js" 'object library - required for allpause 500 'give time to load filejsexternal "/iro.min.js" 'required for COLORWHEELpause 500 'give time to load filegosub screen 'send screen output to browserwait 'wait for interrupt eventschange:if HtmlEventVar$="rgb$" then' wlog rgb$ 'uncomment to show returned rgb$ values in wlog window if neo=1 then neo.strip 0, pixels-1,val("&h"+rgb$) 'update neo-pixel LEDs if sonoff=1 then sonoffb1.rgb val("&h"+rgb$) 'update sonoff LEDsendifif autosave=1 then timer0 delay, savepause 10returnsave:onerror skipfile.save filename$ rgb$ timer0 0returnscreen:clsa$="<br>"if title$<>"" then a$=a$ + |<div style='display: table; margin-right: auto; margin-left: auto;font-size: 110%;'>| a$=a$ + |<font color="teal">|+title$+|</font><br>| 'else a$=a$+"<br>" a$=a$ + |</div><br>|endifa$=a$ + |<div style='display: table; margin-right: auto; margin-left: auto;'>|a$=a$ + |@COLORWHEEL(rgb$, |+rgb$+|, 200)|a$=a$ + |</div><br>|html a$returnend '-----------end------------