I'm working on a project that is going to have a couple NeoPixel strips attached to it. I want to have one of the strips run a rainbow cycle. First I wrote a simple Arduino program to make what I wanted work (attached; rename to ".ino").
Then I tried to move as much of the logic to my library as possible. It seems that I ether screwed something up or you can't access a NeoPixel from within a library. I tried a bunch of stuff including using a pointer (which I don't really understand) and couldn't get it to work. Please help!
I've had all kinds of problems with my program compiling but not being valid and bricking my ProMicro. Fortunately resetting the pro micro lets me upload a new code. This code will upload without bricking the ProMicro but it doesn't do anything. The LED is off.
New INO file:
#include <Adafruit_NeoPixel.h>
#include <YaNeoPixelCycle.h>
YaNeoPixelCycle cycle(8, 3, 255, 100, 20, 200, false, 10);
void setup() {
Serial.begin(9600);
cycle.init();
}
void loop() {
cycle.tryStep();
}
Library .h file
/*
Youkai's Artificery NeoPixel cycle library.
A super basic RGB LED cycle.
*/
#ifndef YaNeoPixelCycle_h
#define YaNeoPixelCycle_h
#include "Arduino.h"
#include "Adafruit_NeoPixel.h"
class YaNeoPixelCycle{
public:
YaNeoPixelCycle(int neoPixelNumLed, int neoPixelControlPin, int saturation, int brightness, int hueStep, int waveStep, boolean useWave, int stepDelay);
void tryStep();
void init();
private:
Adafruit_NeoPixel _neoPixel;
unsigned int _ledHue;
int _saturation;
int _brightness;
int _hueStep;
int _waveStep;
boolean _useWave;
};
#endif
Library .cpp file
/*
Youkai's Artificery NeoPixel cycle library.
A super basic RGB LED cycle.
*/
#include "Arduino.h"
#include "Adafruit_NeoPixel.h"
#include "YaNeoPixelCycle.h"
YaNeoPixelCycle::YaNeoPixelCycle(int neoPixelNumLed, int neoPixelControlPin, int saturation, int brightness, int hueStep, int waveStep, boolean useWave, int stepDelay){
Adafruit_NeoPixel _neoPixel(neoPixelNumLed, neoPixelControlPin, NEO_RGBW + NEO_KHZ800);
_ledHue = 0;
_saturation = saturation;
_brightness = brightness;
_hueStep = hueStep;
_waveStep = waveStep;
_useWave = useWave;
}
void YaNeoPixelCycle::init(){
_neoPixel.begin();
_neoPixel.show();
}
void YaNeoPixelCycle::tryStep(){
Serial.println(_ledHue);
_ledHue += _hueStep;
_neoPixel.fill(_neoPixel.ColorHSV(_ledHue, _saturation, _brightness));
_neoPixel.show();
}