Good evening all. Thanks to the help of this board’s users, I was able to successfully convert an arduino uno controlled project to a Photon project, at least in the hardware department. Now I struggle with the software side. I’m utilizing the FastLED library for my light display and what I had hoped to be a copy and paste kinduva night has turned into one failed compile after another. I’ve tried using other people’s samples and then tried adapting but failed there to. I’ve pared things down to what I consider my simplest display, with a focus on color palettes with the occasional twinkle on a WS2812b strip of LEDs:
//This #include statement was automatically added by the Particle IDE.
#include <FastLED.h>
#include "Particle.h"
FASTLED_USING_NAMESPACE;
#define LED_PIN 4
#define COLOR_ORDER GRB
#define CHIPSET WS2811
#define NUM_LEDS 300 //88 for testing, 300 for prodction
#define BRIGHTNESS 150
#define FRAMES_PER_SECOND 30
bool gReverseDirection = false;
unsigned long previousMillis = 0;
unsigned long currentMillis;
unsigned long twinkleMillis = 0;
int mode;
long totalModes = 3;
NSFastLED::CRGB leds[NUM_LEDS];
CRGBPalette16 gPal;
void setup() {
delay(3000); // sanity delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
//FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
randomSeed(analogRead(0));
//Serial.begin(9600);
mode = random(totalModes);
}
extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
void loop()
{
currentMillis = millis();
switch (mode) {
case 0:
runRainbow();
twinkle();
break;
case 1:
runPalette(leds, NUM_LEDS, gGradientPalettes[0]);
twinkle();
break;
case 2:
runPalette(leds, NUM_LEDS, gGradientPalettes[1]);
twinkle();
break;
}
}
void runColor(NSFastLED::CRGB color) {
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
fill_solid(leds, NUM_LEDS, color); //
FastLED.show();
}
}
void runRainbow() {
if (currentMillis - previousMillis >= 30) {
previousMillis = currentMillis;
static uint8_t hue = 0;
fill_rainbow(leds, NUM_LEDS, hue++);
FastLED.show();
}
}
void twinkle() {
//create random twinkle
int rp = random(500,2000);
if (currentMillis - twinkleMillis >= rp) {
twinkleMillis = currentMillis;
int pixel = random(NUM_LEDS);
leds[random(NUM_LEDS)] = CRGB::White;
FastLED.show();
}
}
void runPalette(NSFastLED::CRGB* ledarray, uint16_t numleds, const CRGBPalette16& gCurrentPalette)
{
if (currentMillis - previousMillis >= 30) {
previousMillis = currentMillis;
static uint8_t startindex = 0;
startindex--;
fill_palette( ledarray, numleds, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND);
FastLED.show();
}
}
DEFINE_GRADIENT_PALETTE( holly_gp) {
0, 0, 255, 0, //green
48, 0, 255, 0, //green
49, 255, 0, 0, //red
64, 255, 0, 0, //red
65, 0, 255, 0, //green
114, 0, 255, 0, //green
115, 255, 0, 0, //red
118, 255, 0, 0, //red
119, 0, 255, 0, //green
168, 0, 255, 0, //green
169, 255, 0, 0, //red
184, 255, 0, 0, //red
185, 0, 255, 0, //green
234, 0, 255, 0, //green
235, 255, 0, 0, //red
255, 255, 0, 0 //red
};
DEFINE_GRADIENT_PALETTE( candycane_gp) {
0 , 128, 128, 128, //white
32 , 128, 128, 128, //white
33 , 255, 0, 0, //red
66 , 255, 0, 0, //red
67 , 128, 128, 128, //white
100 , 128, 128, 128, //white
101 , 255, 0, 0, //red
134 , 255, 0, 0, //red
135 , 128, 128, 128, //white
168 , 128, 128, 128, //white
169 , 255, 0, 0, //red
202 , 255, 0, 0, //red
203 , 128, 128, 128, //white
236 , 128, 128, 128, //white
237 , 255, 0, 0, //red
255 , 255, 0, 0 //red
};
DEFINE_GRADIENT_PALETTE( snowynight_gp) {
0, 163, 182, 199,
41, 188, 192, 200,
117, 117, 157, 240,
204, 117, 224, 240,
255, 163, 182, 199
};
DEFINE_GRADIENT_PALETTE( silvergold_gp) {
46, 191, 201, 224,
127, 255, 236, 133,
204, 191, 201, 224
};
const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
holly_gp,
candycane_gp,
snowynight_gp,
silvergold_gp
};
This particular sketch gives me one error: ‘runPalette’ was not declared in this scope. The line it references occurs in the loop(); If I comment out the runPalette calls, it compiles fine.
I suspect this boils down to a lack of understanding in the syntax department from the arduino to the Photon. Other quicky tests I’ve run break whenever a function with dynamic variables are used.
So, am I just writing this wrong? Please help.