-
-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[T-Embed-CC1101] Encoder RGB LED Support #563
Closed
Closed
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e26582e
Initial work on RGB LED
rouing aa1b219
Use Fill instead of setting a single LED.
rouing 57ef1ae
Added brightness controls
rouing 36fb52e
Change to FastLED Library
rouing 46ec25e
Oops
rouing 0e652dc
Update the README.md to include noted support for the RGB LED
rouing 281dc0c
fix header file
rouing eec1e84
Merge branch 'pr3y:main' into dev-rgb
rouing 1ca2919
Change RGB order to GRB for TBed-CC
rouing 2da8e31
Merge branch 'pr3y:main' into dev-rgb
rouing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,4 +135,4 @@ build_flags = | |
|
||
lib_deps = | ||
${env.lib_deps} | ||
xylopyrographer/LiteLED@^1.2.0 | ||
fastled/FastLED @3.9.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,110 @@ | ||
#ifdef HAS_RGB_LED | ||
// By @IncursioHack - github.com/IncursioHack | ||
#include <LiteLED.h> | ||
#include <FastLED.h> | ||
#include "core/display.h" | ||
#include "core/globals.h" | ||
#include "led_control.h" | ||
|
||
// 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 | ||
#ifdef T_EMBED_1101 | ||
#define LED_TYPE WS2812B | ||
#define LED_ORDER GRB | ||
#define LED_TYPE_IS_RGBW 0 | ||
#define LED_COUNT 8 | ||
#else | ||
#define LED_TYPE SK6812 | ||
#define LED_ORDER RGB | ||
#define LED_TYPE_IS_RGBW 1 | ||
#define LED_COUNT 1 | ||
#endif | ||
|
||
#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) | ||
#define LED_BRIGHT_DEFAULT 245 | ||
|
||
LiteLED myLED( LED_TYPE, LED_TYPE_IS_RGBW ); // Cria o objeto LiteLED com o nome "myLED" | ||
int brightness = 75; | ||
|
||
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 | ||
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; | ||
} | ||
|
||
void setColor(CRGB c) | ||
{ | ||
color = c; | ||
for(int i = 0; i < LED_COUNT; i++){ | ||
leds[i] = color; | ||
} | ||
FastLED.show(); | ||
} | ||
|
||
void setBrightness(int b) | ||
{ | ||
brightness = b; | ||
FastLED.setBrightness(brightness); | ||
FastLED.show(); | ||
} | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,14 @@ | ||
#ifndef __LED_CONTROL_H__ | ||
#define __LED_CONTROL_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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to use the LED_TYPE as condition instead of T-EMBED? ( I'm trying to remove as much Device related MACROS from the ./src/ files and make it as generic as possible)
Otherwise we would need to add more devices in here when we could be declaring this MACRO on platformio.ini..
I would suggest to use like:
and in cardputer/platformio.ini add
-DLED_TYPE=SK6812
after-DHAS_RGB_LED=1
and in t-embed/platformio.ini add
-DLED_TYPE=WS2812B
if other LED models compatible with FastLED come, we can just make the proper setup in the platformio