Project - Colour Changer

Sequences through the RGB colours.of Neo-pixels or Sonoff B1 Lamps.
Might be described as blending between the different colours  (see demo video).
Two such devices can provide almost infinite and endless colour combinations.

Simple at first glance, but some things may be worth worth a longer look.
The diagram (from a Wikipedia colour wheel) shows the precise relationship between the colour hues and 6 distinct 'phases' of the 3 RGB primary colours.

Active sliders cause continual value changes when moved, not just on release.
The Speed slider is rotated 180 degrees to effect an increase of speed.

The Speed control adjusts the rate of change of the discrete steps, by changing the pause between each individual step. It allows smoothly slowing down to almost imperceptible changes, which tempts periodic glances of interest.  
 
The 24bit RGB colour values offer 0 to 255 discrete steps of brightness levels.

The Brightness control reduces the peak brightness level by decreasing the required number of discrete steps. This also affects the colour-change speed, because although the rate of change stays the same, there will be less steps between phases.
This is easily shown by setting the Speed slider at it fastest (right) while first trying the Brightness at dim (left), then brighter.

The startup speed and brightness can be set at the top of the script.
If title$ is non-blank it will be displayed.

You can set the script name into Config Autorun for automatic startup rather than needing to Run it from the browser each time.
In which case you may wish to enter credentials to automatically log on to your router and display the Output control page.
So a word of caution for Sonoff B1 users... be sure you can connect to the device in the browser before you set it to Autorun, because shorting TX and RX together to prevent Autorun on a Sonoff lamp is not quite so straightforward as on other devices.

Make sure to set either neo=1 or sonoff=1 according to which type of RGB device you are using, otherwise you won't see anything.
neo=1                                             'set=1 if using neo-pixels
sonoff=0                                          'set=1 if using a Sonoff B1 Lamp


Basic:
'RGB Colour Changer for NeoPixels or Sonoff B1 Lamps - Electroguard - Developed on Annex 1,41 beta 2
title$="RGB Colour Changer"        'title that will be displayed if not blank
neo=1                                         'set=1 if using neo-pixels
sonoff=0                                      'set=1 if using a Sonoff B1 Lamp
l=50                                            'l (lux) = brightness from 0 (off) to 255 (max)
speed=150                                   'startup colour-change delay
phase=rnd(6)+1                            'random startup colour
mode=1
r=0:g=0:b=0
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 ,0,0,0            'turn all pixels off
endif
if sonoff=1 then
 sonoffb1.init                                'initialise Sonoff B1 Lamp
 sonoffb1.rgb 0,0,0                        'turn all LEDs off
 sonoffb1.white 0,0                        'turn white LEDs off
endif
HtmlEventVar$=""
onhtmlchange change                   'subroutine branch to action controller changes
gosub screen                                'send screen output to browser
gosub blend                                  'colour-changing routine
wait


change:
if sonoff=1 then cmd$="sonoffb1.rgb R,G,B"
if neo=1 then cmd$="neo.strip 0,pixels-1,R,G,B"
command cmd$
refresh
return

blend:
while mode=1
select case phase
 case 1: r=l: b=0: if g>=l then phase=2 else g=g+1
 case 2: g=l: b=0: if r<=0 then phase=3 else r=r-1
 case 3: r=0: g=l: if b>=l then phase=4 else b=b+1
 case 4: r=0: b=l: if g<=0 then phase=5 else g=g-1
 case 5: g=0: b=l: if r>=l then phase=6 else r=r+1
 case 6: r=l: g=0: if b<=0 then phase=1 else b=b-1
end select     
if neo=1 then cmd$="neo.strip 0,pixels-1,R,G,B"
if sonoff=1 then cmd$="sonoffb1.rgb R,G,B"
command cmd$
pause speed
wend
return

screen:
cls
a$=""
a$=a$+|<br>|
a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 110%'>|
if title$<>"" then a$=a$+|<font color="teal">|+title$+|</font><br>| else a$=a$+"<br>"
a$=a$+|<br><br>|
a$=a$+|</div>|
a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;'>|
a$=a$+replace$(slider$(l, 0, 255,"L"), "onchange", "oninput") + |<br>|
a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 80%'>|
a$=a$+|<font color="black">|+" Brightness"+|</font><br><br>|
a$=a$+|</div>|
a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;'>|
a$=a$+replace$(slider$(Speed,0,999,"S"), "onchange", "oninput") +|<br>|
a$=a$+cssid$("s","transform: rotate(180deg);")
a$=a$+|</div>|
a$=a$+|<div style='display: table; margin-right: auto; margin-left: auto;font-size: 80%'>|
a$=a$+|<font color="black">|+" Speed"+|</font><br><br>|
a$=a$+|</div>|
html a$
return

end  '-----------end------------