Demo
Yes, the STM8 less than $1 board can do it
- shading colors of 60 LEDs by addressing every of them with the full 24 bits resolution.
Firmware
- The WS2812B bitbanging was detailed on the Hello Mesh Log
- The 60 x 3 BYTEs info for RGB of every LED are first updated in the STM8 memory, then sent out.
Shading colors
What might look sophisticated for an LED application is a basic operation for a graphics application background
//inputs: the leds section to use defined by which led to start with and which one to end before
//inputs: The color of the first led to use and the color of the last led to use
//action: updates the leds memory with the first and last led colors and all intermediate leds are interpolated
//comment: This function does not send the led data bits on the bus, so that multiple operations can
// be applied before sending the whole result together with SendLedsArray();
void rgb_Shade(BYTE LedStart, BYTE LedEnd, RGBColor_t ColorStart, RGBColor_t ColorEnd)
{
int nbLeds = LedEnd - LedStart;
BYTE LedId = LedStart;
for(int iCount=0;iCount<nbLeds;iCount++)//0-10
{
RGBColor_t Ci = rgb_ColorScale(iCount,nbLeds,ColorStart,ColorEnd);
rgb_SetColors(LedId,Ci);
LedId++;
}
}
- The rgb_Shade() function interpolates a range of LED colors
//input : two colors, and ratio integers
//output : the interpolaetd color
//Sets the interpolated color between Colors Start and End, to the ratio of iCount/nbCount
RGBColor_t rgb_ColorScale(int iCount,int nbCount,RGBColor_t ColorStart,RGBColor_t ColorEnd)
{
RGBColor_t resColor;
int Red = (ColorEnd.R - ColorStart.R);//255
Red = Red * iCount;//0 - 2550
Red = ColorStart.R + (Red / (nbCount - 1));//0 - 255
resColor.R = Red;
int Green = (ColorEnd.G - ColorStart.G);//255
Green = Green * iCount;//0 - 2550
Green = ColorStart.G + (Green / (nbCount - 1));//0 - 255
resColor.G = Green;
int Blue = (ColorEnd.B - ColorStart.B);//255
Blue = Blue * iCount;//0 - 2550
Blue = ColorStart.B + (Blue / (nbCount - 1));//0 - 255
resColor.B = Blue;
return resColor;
}
- The rgb_ColorScale() interpolates one color to assign to every intermediate LED, which is interpolated between the start and the end color
Animation
- Although we address 60 Leds here, every with a different color, the information needed is parametric so very small and packed in few bytes to be sent in a small rf packet.
- That could display smart information such as the Traffic conditions on the every day drive through path, or a heat map,...
- The animation in the video has another loop on top, that interpolates the end color from Blue to RED, which is then fed as ColorEnd to the rgb_shade() function
Source code
- Just to mention that the complete project ready to flash on an STM8 with the IAR studio is part of the IoT_Frameworks github, namely in the rgb_led_bar folder
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.