Hi all,
In a project i'd like to be able to change the color of a (WS2812B) 'status LED' easily.
In other words, i'm using a (single) ws2812B to show the current status of my code, i.e.:
Connecting (Orange)
Running (Green)
Error (Red)
As the status will change throughout several parts of my main code, I'd like to make a simple function to easily make a call to change the color of the LED.
Also, I'd like to define the exact colors in the header of my code to make it easy to adapt (or add) colors later on.
So, I was thinking of doing something like this:
In the header define:
int ConnectingColor[3] {255, 105, 0}; //Orange color in RGB format
int RunningColor[3] {0, 255, 0}; //Green color in RGB format
int ErrorColor[3] {255, 0, 0}; //Red color in RGB format
Then, write some function to do the following:
void ChangeColor(MachineStatus){
switch (MachineStatus){
case Connecting:
leds[0] = ConnectingColor; //Make status LED orange
break;
//
case Running:
leds[0] = RunningColor; //Make status LED green
break;
//
case Error:
leds[0] = ErrorColor; //Make status LED red
break;
}
FastLED.show();
}
Then, within my main code I'd like to be able to call the function like this:
ChangeColor(Error)
To make the LED change to the appropriate color.
First questions:
- How to define the colors in the header? Did i do it the right way?
- How to declare the variable used as argument for the 'ChangeColor' function (the 'MachineStatus' argument), as this will be used as some kind of word/keyword.
- How to use the color definitions in the header to actually change the color (with fastled, default is something like: 'CRGB::Red', but now I'd like to use the personally defined RGB mix.)
Thanks in advance