Thanks for the replies! The FastLED works with no "ghost LEDs", but I still have some questions:
When changing leds[some_led_index].r
, it actually changes the green value of the led. leds[some_led_index].g
changes red. blue works normally. Is there anyone having same problems? Thanks.
This is the current settings I'm using:
#define M5_NEO_NUM 10
#define M5_NEO_PIN 15
CRGB leds[M5_NEO_NUM];
void setup()
FastLED.addLeds<SK6812, M5_NEO_PIN>(leds, M5_NEO_NUM);
// other setups...
}
Compiler complains that No hardware SPI pins defined. All SPI access will default to bitbanged output
, so I also tried WS2811
, but the same problem continues.
The revelant code:
void setLedSingleChannelValue(int led_no, String channel, int val) {
Serial.println("led_no " + (String)led_no + ", channel " + channel + ", val " + (String)val);
if (channel == "R") {
if (led_no < 10) {
leds[led_no].red = val;
}
else {
if (led_no == 10 || led_no == 11) {
for (int i = 0; i < 5; ++ i) {
leds[i].red = val;
}
}
if (led_no == 10 || led_no == 12) {
for (int i = 5; i < 10; ++ i){
leds[i].red = val;
}
}
}
}
else if (channel == "G") {
if (led_no < 10) {
leds[led_no].g = val;
}
else {
if (led_no == 10 || led_no == 11) {
for (int i = 0; i < 5; ++ i) {
leds[i].g = val;
}
}
if (led_no == 10 || led_no == 12) {
for (int i = 5; i < 10; ++ i){
leds[i].g = val;
}
}
}
}
else if (channel == "B") {
if (led_no < 10) {
leds[led_no].b = val;
}
else {
if (led_no == 10 || led_no == 11) {
for (int i = 0; i < 5; ++ i) {
leds[i].b = val;
}
}
if (led_no == 10 || led_no == 12) {
for (int i = 5; i < 10; ++ i){
leds[i].b = val;
}
}
}
}
FastLED.show();
delay(5);
}
void checkAndSetLedSingleChannel(int led_no, String channel, int delta) {
int check_led_no = (led_no < 10) ? led_no : (led_no == 12) ? 9 : 0;
int currentValue = getLedSingleChannelValue(check_led_no, channel);
int afterValue = currentValue + delta;
afterValue = (afterValue < 0) ? 0 : (afterValue > 255) ? 255 : afterValue;
setLedSingleChannelValue(led_no, channel, afterValue);
}
void menu_setLedSingleChannel(int led_no, String channel) {
ezMenu submenu(getLedHeaderText(led_no, "Set"));
submenu.txtSmall();
submenu.buttons("-1 # -10 # Back | OK # # +1 # +10 # -50 # +50 # ");
submenu.addItem(channel + " | " + channel + "\t" + (String)getLedSingleChannelValue(led_no, channel));
while(submenu.runOnce()) {
String pickButton = submenu.pickButton();
if (pickButton == "-1") {
checkAndSetLedSingleChannel(led_no, channel, -1);
}
else if (pickButton == "+1") {
checkAndSetLedSingleChannel(led_no, channel, 1);
}
else if (pickButton == "-10") {
checkAndSetLedSingleChannel(led_no, channel, -10);
}
else if (pickButton == "+10") {
checkAndSetLedSingleChannel(led_no, channel, 10);
}
else if (pickButton == "-50") {
checkAndSetLedSingleChannel(led_no, channel, -50);
}
else if (pickButton == "+50") {
checkAndSetLedSingleChannel(led_no, channel, 50);
}
submenu.setCaption(channel, channel + "\t" + (String)getLedSingleChannelValue(led_no, channel));
delay(20);
}
}
// The program enters from this function.
void menu_setLed(int led_no) {
/*
ez.msgBox("Set LED#" + (String)led_no,
"You have picked LED#" + (String)led_no);
*/
ezMenu submenu(getLedHeaderText(led_no, "Set"));
submenu.txtSmall();
submenu.buttons("up # Back # Select # # down #");
submenu.addItem("R | R\t" + (String)getLedSingleChannelValue(led_no, "R"));
submenu.addItem("G | G\t" + (String)getLedSingleChannelValue(led_no, "G"));
submenu.addItem("B | B\t" + (String)getLedSingleChannelValue(led_no, "B"));
while(submenu.runOnce()) {
String picked = submenu.pickName();
if (picked == "black") {
if (picked == "R" | picked == "G" || picked == "B") {
menu_setLedSingleChannel(led_no, picked);
}
delay(20);
}
}