Hello everyone!
Today I got an error, whilst programming a ledstrip that uses FastLed.H.
First I used a NeoPixel Ledstrip from Adafruit (144 Leds), and then the code worked correctly, but when I added Fastleds (I got a few more led strips of those than the NeoPixel from Adafruit), and the leds won't change the correct ones into the appropriate color.
Do I write wrong from the ledWrite Method towards the SetSingleFastLed method? Or is the error in the variable type?
Code:
#include <Adafruit_NeoPixel.h>
#include <FastLED.h>
#define NumberOfLedsOnFastLedStrip 60
#define DataPinForFastLedLedstrip 5
CRGB FastLeds[NumberOfLedsOnFastLedStrip];
#define TotalNumberOfLeds (144)
#define InputPin (9)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(TotalNumberOfLeds, InputPin, NEO_RGB + NEO_KHZ800);
byte bytesReceived[5];
int coupeNr;
int currentCapacity;
int lengthCoupe;
int startingPoint;
void UpdateStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// If NeoPixel Is Defined
strip.show();
#endif
}
void SetSingleNeoPixel(int NeoPixel, byte G, byte R, byte B) {
#ifdef ADAFRUIT_NEOPIXEL_H
// If NeoPixel Is Defined
strip.setPixelColor(NeoPixel, strip.Color(G, R, B));
UpdateStrip();
#endif
}
void SetSingleFastled(int FastLed, uint8_t R, uint8_t G, uint8_t B)
{
//FastLeds[FastLed].setRGB(R,G,B);
FastLeds[FastLed].r = R;
FastLeds[FastLed].g = G;
FastLeds[FastLed].b = B;
FastLED.show();
}
void SetAllNeoPixels(byte G, byte R, byte B) {
for (int i = 0; i < TotalNumberOfLeds; i++ ) {
SetSingleNeoPixel(i, G, R, B);
}
UpdateStrip();
}
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DataPinForFastLedLedstrip>(FastLeds, NumberOfLedsOnFastLedStrip);
strip.begin();
strip.setBrightness(10);
SetAllNeoPixels(255, 255, 255);
strip.show();
Serial.begin(9600);
fill_solid(FastLeds, 60, CRGB(255, 0, 0));
FastLED.show();
delay(2000);
fill_solid(FastLeds, 60, CRGB(0, 0, 0));
FastLED.show();
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
while (Serial.available() > 0) {
Serial.readBytes(bytesReceived, 5);//lees de bytes van serial en sla ze op in een array
}
delay(2);
coupeNr = bytesReceived[0];
currentCapacity = bytesReceived[1];
lengthCoupe = bytesReceived[2];
byte startingPointHigh = bytesReceived[3];
byte startingPointLow = bytesReceived[4];
startingPoint = (startingPointHigh << 8) | startingPointLow; // Because starting point can be bigger than 255, we will need to apply Bit Manipulation
ledWrite(coupeNr, currentCapacity, lengthCoupe, startingPoint);
}
}
void ledWrite(int coupeInput, int peopleInput, int coupeLength, int startingPoint) {
int R;
int G;
int B;
if (peopleInput < 100) {
R = 2.5 * peopleInput;
G = 255 - (2.5 * peopleInput);
B = 0;
}
if (peopleInput >= 100) {
R = 255;
G = 0;
B = 0;
}
uint8_t fastR = R;
uint8_t fastG = G;
uint8_t fastB = B;
for (int i = (coupeLength * coupeInput) + startingPoint; i < coupeLength + (coupeInput * coupeLength) + startingPoint; i++) { //berekening om de LEDs op de juiste plek aan te zetten
// SetSingleNeoPixel(i, G, R, B);
SetSingleFastled(i, R, G, B);
}
}
I already looked around for the reason, and tried a few CRGB functions out, but they did not fix the problem. I even made Unsigned Ints before the for loop, but it still did not work.
The ledstrip works though when I upload it to the Arduino (with the Fill_Solid Function).
So my question is: Can someone give me a few pointers on where the error lies, or show me what I am doing wrong?
Thank you all in advance, and I wish you all a nice day.