In the function sinFunc there are 2 lines that follow the pixel reference examples but yield no results.
I want to understand the syntax error that I've made here.
The serial print show that the color[] CHSV array is correct but the outcome is 0 to all elements of led[] - the CRGB array.
Thank you for your help
#include <FastLED.h>
#define LEDTYPE WS2812B
#define PL 9 // LED pin
#define STRIP 60 //num LED in strip
#define NOG 3
#define GROUP_SIZE 7
CRGB led[STRIP];
byte hue;
byte sat;
byte val;
CHSV ledHSV[STRIP] = CHSV(hue, sat, val);
bool even;
int ID[NOG];
int groupNum;
CHSV color[NOG];
int lastGroup = STRIP % GROUP_SIZE;
int colorIndexLastGroup = ((STRIP - lastGroup / GROUP_SIZE) % NOG + 1);
bool colorReady = false;
int colorIndex = 0;
void setup() {
Serial.begin(9600);
delay(200);
Serial.println("setup");
FastLED.addLeds<LEDTYPE, PL, GRB>(led, STRIP); //strip details
if (STRIP % 2 == 0) {
even = true;
} else {
even = false;
}
}
void makeColor(int groupNum, byte hue, byte sat, byte val) {
color[groupNum - 1] = CHSV(150, sat, val); // -1 so that the array starts at 0
color[groupNum - 1].hue = (byte) 150;
}
void sinFunc(int counter) {
for (int j = 0; j < GROUP_SIZE; j+=GROUP_SIZE) {
// led[counter * GROUP_SIZE + j] = CHSV(color[colorIndex].hue, color[colorIndex].sat, 255 * sin(j * PI / GROUP_SIZE)); //first problematic line
led[counter * GROUP_SIZE + j].setHSV(color[colorIndex].hue, color[colorIndex].sat, 255 * sin(j * PI / GROUP_SIZE)); //second problematic line
Serial.print("led number: ");
Serial.println(counter * GROUP_SIZE + j);
Serial.print("colorIndex: ");
Serial.println(colorIndex);
Serial.print("color hue: ");
Serial.println(color[colorIndex].hue); //should not be 150
Serial.print("color sat: ");
Serial.println(color[colorIndex].sat); //should not be 150
Serial.print("color val: ");
Serial.println(color[colorIndex].val); //should not be 150
Serial.println("red: ");
Serial.println(led[counter / GROUP_SIZE + j].red);
Serial.println("green: ");
Serial.println(led[counter / GROUP_SIZE + j].green);
Serial.println("blue: ");
Serial.println(led[counter / GROUP_SIZE + j].blue);
}
}
void loop() {
if (!colorReady) {
makeColor(1, 220, 250, 255);
colorReady = true;
}
for (int i = 0; i < (STRIP - lastGroup) / GROUP_SIZE; i++) {
sinFunc(i);
colorIndex++;
if (colorIndex == NOG) {
colorIndex = 0;
}
}
// setLastGroup(lastGroup);
FastLED.show();
delay(1000);
}