Hey,
i am trying to build the Hyperloop tunnel made by flighttest (LED Art you can fly through !?! / DIY Tinywhoop Tunnels - YouTube). They are using 5 nano's to control 5 strips. I want to save money and use only one nano, but 5 digital outputs and loop through them. The important thing is, that all strips must show different outputs...
Here is my code so far... but it is not working like I want it to(all strips show the same thing at the same time)... i have no idea if something like this is even possible... so feel free to share your opinion
#include <FastLED.h>
#include <FastPin.h>
// using a FastLED Implementation
//
// Dean Nicholson, April 2017
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
// LED strips that randomize the passing of "stars"
#define DATA_PIN_2 2 //D2
#define DATA_PIN_3 3 //D3
#define DATA_PIN_4 4 //D4
#define DATA_PIN_5 5 //D5
#define DATA_PIN_6 6 //D6
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 117
// Star Parameters
#define LEAD_LEDS 7 // How many LEDs represent the star
#define MAX_STAR_SPEED 5 // max 5?
#define MIN_STAR_SPEED 3 // min 2?
#define STARS_PER_STRAND 3 // Increase for longer strands
CRGB starLeds[NUM_LEDS + LEAD_LEDS + 3];// Allow for a buffer at the end of the string to avoid congrunet memory overrun
#define INIT_BRIGHTNESS 200
#define FRAMES_PER_SECOND 320
//#define FADE_SPEED 40
long randNumber;
// Starfield Variables
uint8_t lastStarPosition[STARS_PER_STRAND];
uint8_t lastStarSpeed[STARS_PER_STRAND];
CRGB lastStarColor[STARS_PER_STRAND];
uint8_t sHue = 160; // Star color hue - Default to blue
uint8_t sSat = 255;
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
int const potPin = A0;
int const potPin1 = A1;
int potVal;
int potVal1;
int FADE_SPEED;
int BRIGHTNESS;
void setup() {
//Serial.begin(19200);
int k;
randomSeed(analogRead(0)); // Randomize from unconnected pin (noise)
delay(1000); // 3 second delay for recovery
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE, DATA_PIN_2, COLOR_ORDER>(starLeds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_3, COLOR_ORDER>(starLeds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_4, COLOR_ORDER>(starLeds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_5, COLOR_ORDER>(starLeds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_6, COLOR_ORDER>(starLeds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set initial master brightness control
FastLED.setBrightness(INIT_BRIGHTNESS);
// Randomize the initial star positions on each line
for (k = 0; k < STARS_PER_STRAND; k++) {
lastStarPosition[k] = random8(0, NUM_LEDS - 2);
lastStarSpeed[k] = random8(MIN_STAR_SPEED, MAX_STAR_SPEED);
}
}
void loop() {
int l;
for (l = 2; l < 6; l++) {
FastPin.SetOutput(l);
starfield();
int r = 0;
r++;
// insert a delay to keep the framerate modest
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 20 ) {
gHue++; // slowly cycle the "base color" through the rainbow
}
// send the 'leds' array out to the actual LED strip
FastLED.show();
}
}
void starfield() {
uint8_t j, k, c;
uint8_t hueValue;
for (k = 0; k < STARS_PER_STRAND; k++) {
fadeToBlackBy( starLeds, NUM_LEDS, FADE_SPEED);
for (j = 0; j < LEAD_LEDS; j++) {
starLeds[j + lastStarPosition[k]] = lastStarColor[k];
}
hueValue = random(0, 255);
if (lastStarPosition[k] > NUM_LEDS) {
lastStarPosition[k] = 0;
lastStarSpeed[k] = random8(MIN_STAR_SPEED, MAX_STAR_SPEED);
lastStarColor[k] = CHSV(hueValue, sSat, INIT_BRIGHTNESS);
} else {
lastStarPosition[k] = lastStarPosition[k] + lastStarSpeed[k];
}
}
}
You are using the same LED array for each strip. Use a different array for each strip and initialize them with different colors before calling FastLED.show().
Be aware of the memory limitations of the Nano. An array of 127 RGB leds uses 127 * 3 = 381 bytes of memory; multiply by 5 and you're using 1905 bytes out of 2048. A receipe for problems.
I ran into this problem...
i can compile and upload with only 100 leds, but no LED's are blinking...
I have to find a way to debug, but the IDE does not support something like this..
#include <FastLED.h>
// using a FastLED Implementation
//
// Dean Nicholson, April 2017
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
// LED strips that randomize the passing of "stars"
#define DATA_PIN_2 2 //D2
#define DATA_PIN_3 3 //D3
#define DATA_PIN_4 4 //D4
#define DATA_PIN_5 5 //D5
#define DATA_PIN_6 6 //D6
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 119
// Star Parameters
#define LEAD_LEDS 7 // How many LEDs represent the star
#define MAX_STAR_SPEED 5 // max 5?
#define MIN_STAR_SPEED 3 // min 2?
#define STARS_PER_STRAND 3 // Increase for longer strands
CRGB starLeds2[NUM_LEDS + LEAD_LEDS + 3];
CRGB starLeds3[NUM_LEDS + LEAD_LEDS + 3];
CRGB starLeds4[NUM_LEDS + LEAD_LEDS + 3];
CRGB starLeds5[NUM_LEDS + LEAD_LEDS + 3];
CRGB starLeds6[NUM_LEDS + LEAD_LEDS + 3];// Allow for a buffer at the end of the string to avoid congrunet memory overrun
#define INIT_BRIGHTNESS 200
#define FRAMES_PER_SECOND 320
#define FADE_SPEED 40
long randNumber;
// Starfield Variables
uint8_t lastStarPosition[STARS_PER_STRAND];
uint8_t lastStarSpeed[STARS_PER_STRAND];
CRGB lastStarColor[STARS_PER_STRAND];
uint8_t sHue = 160; // Star color hue - Default to blue
uint8_t sSat = 255;
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
void setup() {
uint8_t k;
randomSeed(analogRead(0)); // Randomize from unconnected pin (noise)
delay(1000); // 3 second delay for recovery
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE, DATA_PIN_2, COLOR_ORDER>(starLeds2, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_3, COLOR_ORDER>(starLeds3, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_4, COLOR_ORDER>(starLeds4, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_5, COLOR_ORDER>(starLeds5, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN_6, COLOR_ORDER>(starLeds6, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set initial master brightness control
FastLED.setBrightness(INIT_BRIGHTNESS);
// Randomize the initial star positions on each line
for (k = 0; k < STARS_PER_STRAND; k++) {
lastStarPosition[k] = random8(0, NUM_LEDS - 2);
lastStarSpeed[k] = random8(MIN_STAR_SPEED, MAX_STAR_SPEED);
}
}
void loop() {
starfield();
// insert a delay to keep the framerate modest
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS( 20 ) {
gHue++; // slowly cycle the "base color" through the rainbow
}
// send the 'leds' array out to the actual LED strip
FastLED.show();
}
void starfield() {
uint8_t j, k, c;
uint8_t hueValue;
CRGB d;
for (d = starLeds2[NUM_LEDS + LEAD_LEDS + 3]; d < starLeds5[NUM_LEDS + LEAD_LEDS + 3]; d++){
for (k = 0; k < STARS_PER_STRAND; k++) {
fadeToBlackBy( d[NUM_LEDS + LEAD_LEDS + 3], NUM_LEDS, FADE_SPEED);
for (j = 0; j < LEAD_LEDS; j++) {
starLeds2[j + lastStarPosition[k]] = lastStarColor[k];
}
hueValue = random(0, 255);
if (lastStarPosition[k] > NUM_LEDS) {
lastStarPosition[k] = 0;
lastStarSpeed[k] = random8(MIN_STAR_SPEED, MAX_STAR_SPEED);
lastStarColor[k] = CHSV(hueValue, sSat, INIT_BRIGHTNESS);
} else {
lastStarPosition[k] = lastStarPosition[k] + lastStarSpeed[k];
}
}
}
}
I think that you need to save approximately 500 bytes to play it safe; that will bring theusage to around 1700 bytes. You will still get warnings from the IDE which will indicate that you can get unexpected behaviour. If you don't get unexpected behaviour, great; if you do get unexpected behaviour, you know the cause.
I would go for a Mega, it will save you a lot of hassles.
@gfvalvo, in that case you might have to take care of the 3.3V to 5V difference. I have no experience with teensies. I know that there is a dedicate board on pjrc's website to take care of it (for certain boards).
You're absolutely right. I usually use an 74AHCT14 for that. Unfortunately, that only has 4 gates per package and OP wants to drive 5 strips. Ah well ...