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.
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$ values endif onhtmlchange change 'subroutine branch to action browser screen changes jsexternal "/html_obj.js" 'object library - required for all pause 500 'give time to load file jsexternal "/iro.min.js" 'required for COLORWHEEL pause 500 'give time to load file gosub screen 'send screen output to browser wait 'wait for interrupt events change: 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 LEDs endif if autosave=1 then timer0 delay, save pause 10 return save: onerror skip file.save filename$ rgb$ timer0 0 return screen: cls a$="<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>| endif a$=a$ + |<div style='display: table; margin-right: auto; margin-left: auto;'>| a$=a$ + |@COLORWHEEL(rgb$, |+rgb$+|, 200)| a$=a$ + |</div><br>| html a$ return end '-----------end------------ |