Have you included the library through the library interface or have you only inserted that code? If you havenât done the former, please do, since thatâs whatâs required to get it working. The libraries youâve included should be on the left pane of the IDE.
@marmageek, get rid of the ânewâ in the Adafruit_Neopixel constructor call on line 17. Also, look at line 11 where the pixel type is defined. It SHOULD read:
@marmageek, I used the included Neopixel example as a template. You cast the pixel type as âTYPEâ instead of PIXEL_TYPE. Look at the very first error in the list!
I do not understand what you are trying to say. I defined (not âcastâ) TYPE as WS2812B and I use TYPE in the constructor. The fact that the demo defines PIXEL_TYPE is irrelevant.
@marmageek, my brain is in park and Iâm misfiring on some cylinders! You are correct. Iâll have to test compile once I get home. Can you compile one of the supplied neopixel examples without errors?
Double-check your declarations. You use new to create/instantiate an object which can then be assigned to a pointer variable. But if you just declare an object of the classâs type directly, you donât use new. For example:
Adafruit_NeoPixel *strip1; // strip1 is a pointer, but not initialized yet
strip1 = new Adafruit_NeoPixel(PIXELS, PIN, TYPE);
// ...or... (notice: _not_ an explicit pointer declaration)
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(PIXELS, PIN, TYPE);
According to that one should do as follows:
Adafruit_NeoPixel *strip1 = new Adafruit_NeoPixel(PIXELS, PIN, TYPE);
Adafruit_NeoPixel strip2(PIXELS, PIN, TYPE);
âŚ
Adafruit_NeoPixel *strip3 = &strip2;
âŚ
strip1 is allocated off the stack.
strip2 is allocated out of code_segment
strip3 is stack pointer
I have a feeling though that my error lies elsewhere. I will post my entire code (current state) here in a bit.
I am still getting these errors: xmastree-01.cpp:3:16: error: âAdafruit_NeoPixelâ was not declared in this scope uint32_t wheel(Adafruit_NeoPixel *unit, uint8_t pos);
// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"
// DEFINITIONS
#define PIN D6
#define PIXELS 150
#define PTYPE WS2812B
#define FRAME_DELAY 33 // framerate = 30 fps
#define MOODS 5
#define MOOD_TIMER 1980 // 60 s
// GLOBALS
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, PTYPE);
Adafruit_NeoPixel strip(PIXELS, PIN, PTYPE);
uint8_t mood; // 0=Jon, 1=Dana, 2=Devin, 3=Kolbe, 4=Kyra
unsigned int tick=0;
unsigned int moodTick=0;
// HELPERS
// Colorwheel implemented 0-255 hue.
uint32_t wheel(Adafruit_NeoPixel *unit, uint8_t pos) {
if(pos<85) return unit->Color(pos*3, 255-pos*3, 0);
else if (pos<170) {
pos -= 85;
return unit->Color(255-pos*3, 0, pos*3);
}
else {
pos -=170;
return unit->Color(0, pos*3, 255-pos*3);
}
}
// Fill the dots one after the other with a color
void wipe(Adafruit_NeoPixel *unit, uint32_t c, uint8_t wait){
for (int i=0; i<unit->numPixels(); i++){
unit->setPixelColor(i,c);
unit->show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(Adafruit_NeoPixel *unit, uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< unit->numPixels(); i++) {
unit->setPixelColor(i, wheel(unit, ((i * 256 / unit->numPixels()) + j) & 255));
}
unit->show();
delay(wait);
}
}
// Mood Funcitons We will run a mood for MOOD_TIMER ticks (i.e., frames).
// Mood Inicitalizers
void (*initMoods[])() ={
initJonsMood,
initDanasMood,
initDevinsMood,
initKolbesMood,
initKyrasMood };
// Moods[] contains an array of function pointers to each mood.
void (*Moods[])() = {
jonsMood,
danasMood,
devinsMood,
kolbesMood,
kyrasMood };
// Jon's Mood
void initJonsMood(){
}
void jonsMood() {
rainbow();
}
// Dana's Mood
void initDanasMood(){
}
void danasMood() {
rainbow();
}
// Devin's Mood
void initDevinsMood(){
}
void devinsMood() {
rainbow();
}
// Kolbe's Mood
void initKolbesMood(){
}
void kolbesMood() {
rainbow();
}
// Kyra's Mood
void initKyrasMood(){
}
void kyrasMood() {
rainbow();
}
// Rainbow mood
void initRainbow(){
}
void rainbow() {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, wheel(&strip, (i+j) & 255));
}
strip.show();
delay(FRAME_DELAY);
}
}
// MAIN
void setup() {
strip.begin();
strip.show();
}
void loop() {
if (++tick%MOOD_TIMER == 0) (*initMoods[++moodTick%MOODS])();
// disptach mood
(*Moods[moodTick%MOODS])();
delay(FRAME_DELAY);
}