60 RGB LEDs shading with that tiny STM8

A project log for Home Smart Mesh

Mesh of sensors, zigbee, custom RF, BT, wifi, all to MQTT Gateways on Raspberry Pi with database, dashboard and webapps.

WassimWassim 04/02/2017 at 10:030 Comments


Yes, the STM8 less than $1 board can do it


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);

//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;


Source code