CHEERLIGHTS for 8266 Basic
Posted: Sun Jan 03, 2016 8:46 am
Hi All - My first post here.
MM - I like what you're doing. Great work!
I've recently been reading about the IOT and came up with a few ideas for projects so I ordered a 'yellow' 8266 test board to have a play with and have spent the last few hours getting to know the quirks and foibles of the 8266 and the 8266 Basic.
[url]Cheerlights[/url] caught my attention and I thought I'd use this as a simple first project. Getting data from the ThingSpeak AOI was laughably easy with ESP8266 Basic and thanks to the extremely free and easy type definitions I could easily do the hex code to decimal conversions (but see my feature request) I needed to drive the PWM outputs.
To use this program properly with standard RGB LEDs you'd need to tweak the resistor values to get more accurate colours from the colour codes, but the plan is to drive a NeoPixel array (ordered yesterday) with these which can use the codes directly with no hex to decimal conversion and will hopefully give a better colour rendition.
I've listed the code twice - First with comments and then a stripped down version for copying to the 8266.
And the minimal version :
MM - I like what you're doing. Great work!
I've recently been reading about the IOT and came up with a few ideas for projects so I ordered a 'yellow' 8266 test board to have a play with and have spent the last few hours getting to know the quirks and foibles of the 8266 and the 8266 Basic.
[url]Cheerlights[/url] caught my attention and I thought I'd use this as a simple first project. Getting data from the ThingSpeak AOI was laughably easy with ESP8266 Basic and thanks to the extremely free and easy type definitions I could easily do the hex code to decimal conversions (but see my feature request) I needed to drive the PWM outputs.
To use this program properly with standard RGB LEDs you'd need to tweak the resistor values to get more accurate colours from the colour codes, but the plan is to drive a NeoPixel array (ordered yesterday) with these which can use the codes directly with no hex to decimal conversion and will hopefully give a better colour rendition.
I've listed the code twice - First with comments and then a stripped down version for copying to the 8266.
Code: Select all
' *****************************************************
' Andy's 8266 CHEERLIGHTS proggie for yellow test board
' V1.00
'
' Colours are off for RGB LED as supplied but could be
' made more accurate by resistor colour value matching.
' Should be more acccurate for NEOPIXEL LEDs which can
' use the colour codes directly with no conversion.
' *****************************************************
'
' Pin definitions for RGB LED outputs
RedPin = 15
GrnPin = 12
BluPin = 13
'
'Lookup string for hex to decimal conversion subroutine
HexConv = 123456789ABCDEF
'
TOP
delay 5000
' Get current Ccheerlights colour code from ThingSpeak API
colcode = readts(key,1417,2)
'
' Simple check to make sure 7 character string returned
if len(colcode) <> 7 then goto TOP
'
' Extract red, green then blue codes from string
' and convert to decimal equivalent.
Tmp1 = mid$(colcode,2,2)
gosub TODEC
RedVal = DecVal
Tmp1 = mid$(colcode,4,2)
gosub TODEC
GrnVal = DecVal
Tmp1 = mid$(colcode,6,2)
gosub TODEC
BluVal = DecVal
'
' Set PWM for each colour
pwo RedPin RedVal
pwo GrnPin GrnVal
pwo BluPin BluVal
'
goto TOP
'
'
'
TODEC
' Extract left then right character from hex pair
LSB = left(Tmp1,1)
MSB = right(Tmp1,1)
' and look for position in hex lookup string
LSB = instr(HexConv,LSB)
MSB = instr(HexConv,MSB)
' Calculate decimal value (16*MSB + LSB)
DecVal = MSB * 16
DecVal = DecVal + LSB
' Double the value as 8266 PWM uses 0 to 511
DecVal = DecVal * 2
return
And the minimal version :
Code: Select all
' *****************************************************
' Andy's 8266 CHEERLIGHTS proggie for yellow test board
' V1.00
' *****************************************************
'
RedPin = 15
GrnPin = 12
BluPin = 13
'
HexConv = 123456789ABCDEF
'
TOP
delay 5000
colcode = readts(key,1417,2)
'
if len(colcode) <> 7 then goto TOP
'
Tmp1 = mid$(colcode,2,2)
gosub TODEC
RedVal = DecVal
Tmp1 = mid$(colcode,4,2)
gosub TODEC
GrnVal = DecVal
Tmp1 = mid$(colcode,6,2)
gosub TODEC
BluVal = DecVal
'
pwo RedPin RedVal
pwo GrnPin GrnVal
pwo BluPin BluVal
'
goto TOP
'
TODEC
LSB = left(Tmp1,1)
MSB = right(Tmp1,1)
LSB = instr(HexConv,LSB)
MSB = instr(HexConv,MSB)
DecVal = MSB * 16
DecVal = DecVal + LSB
DecVal = DecVal * 2
return