Thanks Jon, for some reason I have been unable to get my noggin around running two animations off the same array…
Trying to understand the multiple array part, running two animations off two separate data pins… basically, combining two sketches into one.
I have been able to combine two sketches but trying to understand the code structure. Trying to make a ‘template’ sketch so I can refer to later on.
On the combined sketch, trying to understand the loop. It has a scan(); and a void scan () as part of the first animation. Should it also have a breathe(); and void breathe () as part of the second animation?
Whenever I keep tinkering around, I just get errors…
(need to get a Github account, sorry)
/*
This is an attempt at combining two individual sketches into one sketch, operating on two pins - 6 and 8
On pin 6, it runs a scanner animation that a set of leds travel back and forth, allowing you to define color, speed and trail length.
On pin 8, it runs an animation that fades between two colors, aloowing you to define colors and speed of transition.
Pin 6 runs an abbreviated and modified sketch that started life as juggle.ino by Mark Kriegsman… and later modified by Andrew Tuline
For additional information on the original sketches, they can be found on their specific GitHub pages:
Mark Kriegsman: kriegsman (Mark Kriegsman) · GitHub
Andrew Tuline: GitHub - atuline/FastLED-Demos: Here's my updated FastLED demos from January, 2017.
Pin 8 runs a modified sketch that started life as test_breath_effect_v2.ino by Marc Miller
For additional information on the original sketches, they can be found on his specific GitHub page:
Marc Miller: marmilicious (Marc Miller) · GitHub
*/
#include “FastLED.h”
// Fixed definitions cannot change on the fly.
#define DATA_PIN_A 6 // Data pin to connect to the strip.
#define DATA_PIN_B 8 // Data pin to connect to the strip.
#define LED_TYPE WS2811 // Style of led strip
#define COLOR_ORDER GRB // Color order of leds
#define NUM_LEDS_A 30 // How many leds are in the first strip’s animation
#define NUM_LEDS_B 30 // How many leds are in the second strip’s animation
// Initialize changeable global variables.
CRGB scanner[NUM_LEDS_A]; // Initialize led array for first animation
CRGB breather[NUM_LEDS_B]; // Initialize led array for second animation
//First Animation ‘scanner’
// Routine specific variables
uint8_t numdots = 1; // Number of dots in use.
uint8_t faderate = 35; // How long should the trails be. Very low value = longer trails.
uint8_t hueinc = 8; // Incremental change in hue between each dot.
uint8_t thishue = 80; // Starting hue - Change number based on ‘rainbow’ HSV value 0=red, 205=purple, etc.
uint8_t curhue = 0; // The current hue
uint8_t thissat = 255; // Saturation of the colour.
uint8_t thisbright = 255; // How bright should the LED/display be.
uint8_t basebeat = 13; // Higher = faster movement.
//Second Animation ‘breather’
// Routine specific variables
static float pulseSpeed = 1;// Larger value gives faster pulse.
uint8_t hueA = 96; // Start hue at valueMin.
uint8_t satA = 255; // Start saturation at valueMin.
float valueMin = 100.0; // Pulse minimum value (Should be less then valueMax).
uint8_t hueB = 80; // End hue at valueMax.
uint8_t satB = 255; // End saturation at valueMax.
float valueMax = 180.0; // Pulse maximum value (Should be larger then valueMin).
uint8_t hue = hueA; // Do Not Edit
uint8_t sat = satA; // Do Not Edit
float val = valueMin; // Do Not Edit
uint8_t hueDelta = hueA - hueB;// Do Not Edit
static float delta = (valueMax - valueMin) / 2.35040238; // Do Not Edit
//setup, called once - where the magic starts to happen
void setup() {
delay(1000); // Power-up safety delay or something like that.
Serial.begin(57600);
LEDS.addLeds<LED_TYPE, DATA_PIN_A, COLOR_ORDER>(scanner, NUM_LEDS_A);// Identifies which data pin the array NUM_LEDS_A is attach to
LEDS.addLeds<LED_TYPE, DATA_PIN_B, COLOR_ORDER>(breather, NUM_LEDS_B);// Identifies which data pin the array NUM_LEDS_B is attach to
}
//loop, runs over and over
void loop() {
/*
This is the code for the first animation
*/
for(int i = 0; i < NUM_LEDS_A; i++) { // This is saying I want the first animation on the pin that has NUM_LEDS_A
scan();
}
}
void scan() { // Several colored dots, weaving in and out of sync with each other
curhue = thishue; // Reset the hue values.
fadeToBlackBy(scanner, NUM_LEDS_A, faderate);
for( int i = 0; i < numdots; i++) {
scanner[beatsin16(basebeat+i+numdots,0,NUM_LEDS_A)] += CHSV(curhue, thissat, thisbright);//beat16 is a FastLED 3.1 function
curhue += hueinc;
}
/*
End of code for the first animation
*/
/*
This is the code for the second animation
*/
for(int i = 0; i < NUM_LEDS_B; i++) {// This is saying I want the first animation on the pin that has NUM_LEDS_B
float dV = ((exp(sin(pulseSpeed * millis()/2000.0PI)) -0.36787944) * delta);
val = valueMin + dV;
hue = map(val, valueMin, valueMax, hueA, hueB); // Map hue based on current val
sat = map(val, valueMin, valueMax, satA, satB); // Map sat based on current val
breather[i] = CHSV(hue, sat, val);
}
/
End of code for second animation
*/
FastLED.show(); //Sends above loop code out to the led strips
//loop starts all over again
}