Post about your Basic project here

Moderator: Mmiscool

User avatar
By AndyGadget
#60208 I first posted here almost a year ago. For various reasons I haven't been doing much makerstuff since then, but I've just picked up the ESP8266 again and am posting an update to my original RGB LED Cheerlights display, now using NeoPixels.

Cheerlights is an IOT colour display. By tweeting a colour name to @cheerlights you can set the colour of all active Cheerlights devices worldwide. More information at http://cheerlights.com/

Neopixels strings and modules are simple to use, a single device using just VCC, 0V and DataIn pin so using one GPIO of the ESP8266. Mike's Basic makes them easy to drive too with a variety of commands to address them.

The program interrogates the ThingSpeak Cheerlights API for the current colour and then displays it on NeoPixels, fading from the previous to the new colour. The way I do the colour change means that the LEDs may pass through another colour on the way, e.g. red to blue will show magenta in passing.

I'm using the 7 NeoPixel disc; 6 + 1 in the middle. Change the 'neo.stripcolor' command in the program to suit the number of LEDs you're using.

Code: Select all'************************************************
' ESP8266 Cheerlights - New Version for V3 Basic
' and Neopixel display with fade between colours
.'************************************************

' Set up Neopixel strip.
neo.setup(15)
neo.cls()

' Initialise colour values
redval = 0
grnval = 0
bluval = 0

[TOP]
   ' Retrieve current hex colour code from
   ' Thingspeak Cheerlights API in form #rrggbb.
   '(Key value can be any string)
   colcode = readts("xxx","1417","2")

   ' Store old colour values
   ' These will be modified in fade loop.
   redvalx = redval
   grnvalx = grnval
   bluvalx = bluval

   'Extract R, G and B bytes from new colour code.
   redval = hextoint(mid(colcode,2,2))
   grnval = hextoint(mid(colcode,4,2))
   bluval = hextoint(mid(colcode,6,2))

   ' Fade routine - output colours increment / decrement to new colour.
   do
      if redvalx > redval then redvalx = redvalx - 1
      if redvalx < redval then redvalx = redvalx + 1
      if grnvalx > grnval then grnvalx = grnvalx - 1
      if grnvalx < grnval then grnvalx = grnvalx + 1
      if bluvalx > bluval then bluvalx = bluvalx - 1
      if bluvalx < bluval then bluvalx = bluvalx + 1

      ' Send intermediate colour to neopixels :
      ' I'm using 7 LED NeoPixel disc numbered 0 to 6.
      neo.stripcolor(0,6,redvalx,grnvalx,bluvalx)
      
      ' Change delay value for fade speed
       delay 30
   
   ' Exit loop when intermediate R, G and B values match new colour.     
   loop until (redvalx = redval) and (grnvalx = grnval) and (bluvalx = bluval)

   delay 5000
goto [TOP]