Hello there,
I have been trying to create a custom library for a project I am doing at work. The code will have to control one or multiple WS2811 LED Strips and multiple RGB-PWM LED Strips. I am stuck at the point of trying to create the class for the WS2811 Strips. Here's my code:
OctagonPanel.cpp
#include "..\FastLED\FastLED.h"
#include <Arduino.h>
#include "OctagonPanel.h"
#include <SoftwareSerial.h>
uint8_t _ledTypes[3][2]{
{255, 255}, //vertikal über Vorgängerled
{180, 180}, //diagonal über Vorgängerled
{255, 0} //horizontal neben Vorgängerled
};
OctagonPanel::OctagonPanel(const uint8_t dataPin, unsigned int numLeds, uint8_t ledDefinerArray[]){
_dataPin = dataPin;
const unsigned int _numLeds = numLeds;
uint8_t _ledDefinerArray[_numLeds];
for(uint8_t i = 0; i < _numLeds; i++){
_ledDefinerArray[i] = ledDefinerArray[i];
}
switch(_dataPin){
case 2:
#define DATA_PIN 2
break;
case 3:
#define DATA_PIN 3
break;
case 4:
#define DATA_PIN 4
break;
case 5:
#define DATA_PIN 5
break;
case 6:
#define DATA_PIN 6
break;
case 7:
#define DATA_PIN 7
break;
}
for(unsigned int j = 0; j <= _numLeds; j++){
_levelMaxTotal = _levelMaxTotal + _ledTypes[_ledDefinerArray[j]][1];
}
}
void OctagonPanel::begin(){
FastLED.addLeds<NEOPIXEL, DATA_PIN>(_leds, _numLeds);
}
void OctagonPanel::show(){
FastLED.show();
}
void OctagonPanel::testFunc(){
for(int i = 0; i <= 10; i++){
Serial.println(_leds[i]);
_leds[i] = CHSV(240, 255,255);
Serial.print("i: ");
Serial.println(i);
Serial.println(_leds[i]);
}
}
OctagonPanel.h
#ifndef OctagonPanel_h
#define OctagonPanel_h
#include <Arduino.h>
class OctagonPanel{
public:
OctagonPanel(const uint8_t dataPin, unsigned int numLeds, uint8_t ledDefinerArray[]);
int getLevelActual();
void setLevel(uint8_t level);
void setHue(uint8_t hue);
void update();
void begin();
void show();
void testFunc();
private:
int _x, _level, _hue, _dataPin;
int _ledsFull, _lastLedFillValue;
int _levelActual, _levelTarget, _numLeds, _levelMax, _levelMaxTotal;
CRGB _leds[16];
int _ledDefinerArray[16];
};
#endif
main.ino
#include "src\FastLED\FastLED.h"
#include "src\LightingControl\OctagonPanel.h"
const unsigned int NUM_LEDS = 16;
const uint8_t DELAY = 10, DATA_PIN = 6, HUE = 240;
uint8_t ledDefinerArray[NUM_LEDS]{0,0,0,0,1,1,1,1,2,2,2,2,0,0,0,0};
OctagonPanel panel1(DATA_PIN, NUM_LEDS, ledDefinerArray);
void setup(){
Serial.begin(9600);
panel1.begin();
Serial.println("Good Morning");
panel1.testFunc();
panel1.show();
}
void loop(){
}
When I compile this code no errors occur and it uploads just fine but the Strip I attached does nothing at all. I have checked the hardware setup by uploading a sketch for the Strip that doesn't use a custom library (so everything just in one sketch) and it works without problems.
I have found a thread that had a very similar problem but his solution didn't work for me: He put the the constructor for the existing Library inside a separate function and not in the constructor of his own library. I did exactly that but nothing changed.
The Serial.print lines I added for debugging give me the expected results so the code runs as intended except for the FastLED library.
My guess is, that I am missing out on some crucial part about how to use a library wthin another but I can't point it down.
Here's a minimal example for the FastLED library i'm trying to use:
#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 1
// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 3
#define CLOCK_PIN 13
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
}
void loop() {
// Turn the LED on, then pause
leds[0] = CRGB::Red;
FastLED.show();
delay(500);
// Now turn the LED off, then pause
leds[0] = CRGB::Black;
FastLED.show();
delay(500);
}
Any help and hints are greatly appreciated!
P.S.: There are seemingly unused variables and functions which are used in other parts of my code I didn't put on here as the provide no relevant information to the problem at hand