enhanced RGB LED control for M5fire

This commit is contained in:
Klaus K Wilting 2020-04-06 11:53:55 +02:00
parent 67cede2886
commit 59930870fd
3 changed files with 13 additions and 6 deletions

View File

@ -4,6 +4,10 @@
#include <SmartLeds.h> #include <SmartLeds.h>
#include "lorawan.h" #include "lorawan.h"
#ifndef RGB_LED_COUNT
#define RGB_LED_COUNT 1
#endif
// value for HSL color // value for HSL color
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm // see http://www.workwithcolor.com/blue-color-hue-range-01.htm
#define COLOR_RED 0 #define COLOR_RED 0

View File

@ -38,7 +38,8 @@
//#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board //#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 100k/100k on board
#define HAS_LED NOT_A_PIN // no on board LED (?) #define HAS_LED NOT_A_PIN // no on board LED (?)
#define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, 10, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15 #define RGB_LED_COUNT 10
#define HAS_RGB_LED SmartLed rgb_led(LED_SK6812, RGB_LED_COUNT, GPIO_NUM_15) // LED_SK6812 RGB LED on GPIO15
#define HAS_BUTTON (39) // on board button A #define HAS_BUTTON (39) // on board button A
// GPS settings // GPS settings

View File

@ -64,8 +64,9 @@ RGBColor rgb_hsl2rgb(float h, float s, float l) {
void rgb_set_color(uint16_t hue) { void rgb_set_color(uint16_t hue) {
if (hue == COLOR_NONE) { if (hue == COLOR_NONE) {
// Off // set Off
rgb_led[0] = Rgb(0, 0, 0); for (int i = 0; i < RGB_LED_COUNT; i++)
rgb_led[i] = Rgb(0, 0, 0);
} else { } else {
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm // see http://www.workwithcolor.com/blue-color-hue-range-01.htm
// H (is color from 0..360) should be between 0.0 and 1.0 // H (is color from 0..360) should be between 0.0 and 1.0
@ -74,7 +75,8 @@ void rgb_set_color(uint16_t hue) {
// cfg.rgblum is between 0 and 100 (percent) // cfg.rgblum is between 0 and 100 (percent)
RGBColor target = rgb_hsl2rgb(hue / 360.0f, 1.0f, 0.005f * cfg.rgblum); RGBColor target = rgb_hsl2rgb(hue / 360.0f, 1.0f, 0.005f * cfg.rgblum);
// uint32_t color = target.R<<16 | target.G<<8 | target.B; // uint32_t color = target.R<<16 | target.G<<8 | target.B;
rgb_led[0] = Rgb(target.R, target.G, target.B); for (int i = 0; i < RGB_LED_COUNT; i++)
rgb_led[i] = Rgb(target.R, target.G, target.B);
} }
// Show // Show
rgb_led.show(); rgb_led.show();