Skip to content

Commit

Permalink
[T-Embed-CC1101] Encoder RGB LED Support (pr3y#628)
Browse files Browse the repository at this point in the history
* T-EMBED-CC1101 RGB LED Support

* it builds and works!
  • Loading branch information
rouing authored Dec 29, 2024
1 parent 63a1be3 commit d474d35
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 71 deletions.
1 change: 1 addition & 0 deletions boards/lilygo-t-embed-cc1101.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ lib_deps =
${env.lib_deps}
lewisxhe/XPowersLib @0.2.6
mathertel/RotaryEncoder @1.5.3
fastled/FastLED @3.9.4
2 changes: 1 addition & 1 deletion boards/m5stack-cardputer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ build_flags =

lib_deps =
${env.lib_deps}
xylopyrographer/LiteLED@^1.2.0
fastled/FastLED @3.9.4
8 changes: 6 additions & 2 deletions boards/pinouts/lilygo-t-embed-cc1101.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ static const uint8_t RX = SERIAL_RX;
// #define HAS_RTC

// RGB LED
// #define HAS_RGB_LED
// #define RGB_LED=21
#define HAS_RGB_LED 1
#define RGB_LED 21
#define LED_TYPE WS2812B
#define LED_ORDER GRB
#define LED_TYPE_IS_RGBW 0
#define LED_COUNT 8

// BadUSB
#define USB_as_HID 1
Expand Down
4 changes: 4 additions & 0 deletions boards/pinouts/m5stack-cardputer.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,9 @@ static const uint8_t _kb_asciimap[128] = {
0 // DEL
};

#define LED_TYPE SK6812
#define LED_ORDER RGB
#define LED_TYPE_IS_RGBW 1
#define LED_COUNT 1

#endif /* Pins_Arduino_h */
4 changes: 2 additions & 2 deletions src/core/menu_items/OthersMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void OthersMenu::optionsMenu() {
{"USB Keyboard", [=]() { usb_keyboard(); }},
#endif
#ifdef HAS_RGB_LED
{"LED Control", [=]() { ledrgb_setup(); }}, // IncursioHack
{"LED FLash", [=]() { ledrgb_flash(); }}, // IncursioHack
{"LED Control", [=]() { ledColorConfig(); }},
{"LED Brightness", [=]() { ledBrightnessConfig(); }},
#endif
#ifndef LITE_VERSION
{"Openhaystack", [=]() { openhaystack_setup(); }},
Expand Down
121 changes: 81 additions & 40 deletions src/modules/others/led.cpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,97 @@
#include "led_control.h"
#ifdef HAS_RGB_LED
// By @IncursioHack - github.com/IncursioHack
#include <LiteLED.h>
#include "core/display.h"
#include <globals.h>
#include "led_control.h"
#include "core/display.h"
#include <FastLED.h>
#define LED_BRIGHT_DEFAULT 245

int brightness = 75;

CRGB leds[LED_COUNT];
CRGB color = CRGB::Red;

CRGB hsvToRgb(uint16_t h, uint8_t s, uint8_t v)
{
uint8_t f = (h % 60) * 255 / 60;
uint8_t p = (255 - s) * (uint16_t)v / 255;
uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
uint8_t r = 0, g = 0, b = 0;
switch ((h / 60) % 6) {
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
case 5: r = v; g = p; b = q; break;
}

CRGB c;
c.red = r;
c.green = g;
c.blue = b;
return c;
}

// Escolha o tipo de LED na lista abaixo.
// Comente todos menos um LED_TYPE.
// #define LED_TYPE LED_STRIP_WS2812
#define LED_TYPE LED_STRIP_SK6812
// #define LED_STRIP_APA106
// #define LED_STRIP_SM16703
void setColor(CRGB c)
{
color = c;
for(int i = 0; i < LED_COUNT; i++){
leds[i] = color;
}
FastLED.show();
}

#define LED_TYPE_IS_RGBW 1 // Se o LED for do tipo RGBW, altere o 0 para 1
#define LED_BRIGHT 245 // Define o brilho do LED. "0" está desligado; 255 pode queimar seus olhos (não recomendado)
void setBrightness(int b)
{
brightness = b;
FastLED.setBrightness(brightness);
FastLED.show();
}

LiteLED myLED( LED_TYPE, LED_TYPE_IS_RGBW ); // Cria o objeto LiteLED com o nome "myLED"

void ledrgb_setup() {
myLED.begin( RGB_LED, 1 ); // Inicialize o objeto myLED. Aqui temos 1 LED conectado ao pino RGB_LED
myLED.brightness( LED_BRIGHT, 1 ); // Ligue o LED
void ledColorConfig()
{
FastLED.addLeds<LED_TYPE, RGB_LED, LED_ORDER>(leds, LED_COUNT); // Initialize the LED Object. Only 1 LED.
setBrightness(brightness); // Set LED Brightness

options = {
{"OFF", [=]() { myLED.brightness( 0, 1 ); }},
{"PURPLE", [=]() { myLED.setPixel( 0, L_PURPLE, 1 ); }},
{"WHITE", [=]() { myLED.setPixel( 0, L_WHITE, 1 ); }},
{"RED", [=]() { myLED.setPixel( 0, L_RED, 1 ); }},
{"GREEN", [=]() { myLED.setPixel( 0, L_GREEN, 1 ); }},
{"BLUE", [=]() { myLED.setPixel( 0, L_BLUE, 1 ); }},
{"OFF", [=]()
{ setBrightness(0); }},
{"PURPLE", [=]()
{ setColor(CRGB::Purple); }},
{"WHITE", [=]()
{ setColor(CRGB::White); }},
{"RED", [=]()
{ setColor(CRGB::Red); }},
{"GREEN", [=]()
{ setColor(CRGB::Green); }},
{"BLUE", [=]()
{ setColor(CRGB::Blue); }},
};
delay(200);
loopOptions(options);
delay(200);
}

void ledrgb_flash() {
myLED.begin( RGB_LED, 1 ); // Inicialize o objeto myLED. Aqui temos 1 LED conectado ao pino RGB_LED
myLED.brightness( LED_BRIGHT_DEFAULT, 1 ); // Ligue o LED
myLED.setPixel( 0, L_PURPLE, 1 );
delay(1000);
myLED.brightness( 0, 1 );
delay(1000);
myLED.brightness( LED_BRIGHT_DEFAULT, 1 );
delay(1000);
myLED.brightness( 0, 1 );
delay(1000);
myLED.brightness( LED_BRIGHT_DEFAULT, 1 );
delay(1000);
myLED.brightness( 0, 1 );
delay(1000);
myLED.brightness( LED_BRIGHT_DEFAULT, 1 );
delay(1000);
myLED.brightness( 0, 1 );
void ledBrightnessConfig()
{

options = {
{"10", [=]()
{ setBrightness(10); }},
{"25", [=]()
{ setBrightness(20); }},
{"50", [=]()
{ setBrightness(50); }},
{"75", [=]()
{ setBrightness(75); }},
{"100", [=]()
{ setBrightness(100); }},
};

delay(200);
loopOptions(options);
delay(200);
}
#endif
36 changes: 10 additions & 26 deletions src/modules/others/led_control.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
#ifndef __LED_CONTROL_H__
#define __LED_CONTROL_H__
#include <globals.h>
#ifdef HAS_RGB_LED
// By IncursioHack @github.com/IncursioHack
#include <Arduino.h>
#include <LiteLED.h>
#include <FastLED.h>

// Escolha o tipo de LED na lista abaixo. Comente todos, exceto o que você está usando.
#define LED_TYPE LED_STRIP_SK6812
// #define LED_STRIP_WS2812
// #define LED_STRIP_APA106
// #define LED_STRIP_SM16703

#define LED_TYPE_IS_RGBW 1 // Se o LED for do tipo RGBW, altere o 0 para 1

// Definição de intensidade de brilho
#define LED_BRIGHT_DEFAULT 245 // Define o brilho padrão do LED. "0" é desligado; 255 pode ser muito brilhante.

// Cores predefinidas para o LED
static const crgb_t L_RED = 0xff0000;
static const crgb_t L_GREEN = 0x00ff00;
static const crgb_t L_BLUE = 0x0000ff;
static const crgb_t L_WHITE = 0xe0e0e0;
static const crgb_t L_PURPLE = 0xff00ff;

// Declaração do objeto LiteLED
extern LiteLED myLED;

// Declarações de funções para controle do LED RGB
void ledrgb_setup();
void ledrgb_flash();
CRGB hsvToRgb(uint16_t h, uint8_t s, uint8_t v);
void setColor(CRGB c);
void setBrightness(int b);
void ledColorConfig();
void ledBrightnessConfig();

#endif
#endif

0 comments on commit d474d35

Please sign in to comment.