Morning Hans,
Sorry I've not written anything these last few days, I've just not had the energy to do much due to a heavy cold (I've gone to work then almost immediately gone to bed),
Yesterday I went right back to basics and rewote the code (albeit for my 75leds) but although not quite what I needed I did get the basic code sorted (and tidied up a bit too), more modification is required and delete the bits of code that I don't really need.
// Testing version, last update (working test_C) (21/9/18)
// this version has short red fuse after rgb sequence
// then runs twinkle and white meteor
// I like this one as it uses if statement to run sequence
#include "FastLED.h"
#define NUM_LEDS 75
CRGB leds[NUM_LEDS];
#define PIN 3
#define Brightness 20
// strip lengths (not used for now, but are needed when using the mirror of Fire)
#define S1 10 //66
#define S2 15 //142
#define S3 15 //71
#define S4 5 //91
#define S5 25 //128
int RunOnce = true ;
void setup()
{
FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(Brightness);
// variables not used for now (may be removed)
int S2a = S1+S2 ;
int S3a = S2a+S3 ;
int S4a = S3a+S4 ;
}
// REPLACE FROM HERE
void loop() {
if (RunOnce == true)
{
StartUp();
RunOnce = false;
}
// TwinkleRandom - twinkle count, speed delay, only one (true/false)
TwinkleRandom(2000, 1, false);
// meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
meteorRain(0x00,0xff,0x00,10, 64, true, 30);
}
void StartUp(){
rgb(2000, 3); // delay time , number of times to flash
// Twinkle - Color (red, green, blue), count, speed delay, only one twinkle (true/false)
Twinkle(0xff, 0xff, 0xff, 1000,1, true); // ff,00,00,10,100,false
// meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
meteorRain(0xff,0x00,0x00,2, 200, true, 30);
//delay (4000);
}
void rgb(int wait, int t)
{
do {
for (int i = 0 ; i <= t; i++){
fill_solid (leds, NUM_LEDS, CRGB( 255, 0, 0));
FastLED.show();
delay (wait);
fill_solid (leds, NUM_LEDS, CRGB( 0, 255, 0));
FastLED.show();
delay (wait);
fill_solid (leds, NUM_LEDS, CRGB( 0, 0, 255));
FastLED.show();
delay (wait);
}
wait =wait/2 ;
}
while (wait >=1);
setAll(0,0,0);
//delay (4000);
}
void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
// setAll(0,0,0);
for (int i=0; i<Count; i++) {
setPixel(random(NUM_LEDS),red,green,blue);
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
delay(SpeedDelay);
}
void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
setAll(0,0,0);
for (int i=0; i<Count; i++) {
setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
showStrip();
delay(SpeedDelay);
if(OnlyOne) {
setAll(0,0,0);
}
}
delay(SpeedDelay);
}
void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
int Pixel = random(NUM_LEDS);
setPixel(Pixel,red,green,blue);
showStrip();
delay(SpeedDelay);
setPixel(Pixel,0,0,0);
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0,0,0);
for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}
showStrip();
delay(SpeedDelay);
}
}
// used by meteorrain
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
strip.setPixelColor(ledNo, r,g,b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}
// REPLACE TO HERE
// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************
// Apply LED color changes
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
I've also had a play with the meteorRain sequence. I changed the parameters it gets sent so that it does it in house. As you can see it changes the RGB codes to random, the result it a random colour every time it runs the code. Kids think its brilliant
.
byte red = random8(255); //0xff;
byte green = random8(255); //0xff;
byte blue = random8(255); //0xff;
byte meteorSize = 10;
byte meteorTrailDecay = 64;
boolean meteorRandomDecay = true;
int SpeedDelay = 30;
Now to add the fire routine and upload it to the 500 leds... Maybe next week (when most of the neighbors are working so they cant see it)
Enjoy your weekend.
Phil