I know this should be simple, but I’m having a hard time figuring it out. Hopefully I can explain it clearly enough.
I have some code that rotates a single light around a circle of 64 WS2811s. I would like it to light up more than one light each time - for instance, five lights - and rotate those around the circle. I know I could put a for loop around the leds[rot] line, but I’m not sure how to handle the “reset” back to zero when the loop hits 63.
Hopefully, I’m pasting this example in correctly.
FastLED_rotation
void rotation() {
animDelay = mappedSpeed;
if (millis()-LastAnim >= animDelay) {
rot = rot + 1;
if (rot > NUM_LEDS - 1){rot = 0;}
fadeToBlackBy( leds, NUM_LEDS, 20);
LastAnim = millis();
leds[rot] += CHSV(gHue, 255, outputBright);
}
}
Sam_Guyer
(Sam Guyer)
July 10, 2018, 2:18am
2
There are a couple of ways you can accomplish that. Do you still want to have the “trail” created by the FadeToBlack call?
marmil
(Marc Miller)
July 10, 2018, 3:10am
3
Here’s some examples that might give you some ideas to try out.
//***************************************************************
// Basic example that repeats colored blocks of random size down
// the strip. The block size is changed every several seconds.
//
// Important to note is there is a check to make sure we don't
// try to write data to pixels that don't exist (ie. values
// equal or greater then NUM_LEDS). Trying to write pixel
// data to pixels that don't exist the causes bad things to
// happen in memory.
//
// Marc Miller, July 2017
// May 2020 - replaced delays with EVERY_N
//***************************************************************
#include "FastLED.h"
#define DATA_PIN 11
#define CLOCK_PIN 13
#define LED_TYPE LPD8806
#define COLOR_ORDER GRB
This file has been truncated. show original
//***************************************************************
// Moving colored bars
// Original code by Richard Bailey, Feb. 2017
//
// Modified to allow a few other options (which might be
// useful for Christmas!)
// You'll probably need to adjust stuff for longer strips. I only
// tested with a tiny 32 pixel setup.
//
// Marc Miller, Dec 2017
//***************************************************************
#include "FastLED.h"
#define DATA_PIN 11
#define CLK_PIN 13
#define LED_TYPE LPD8806
#define COLOR_ORDER GRB
#define NUM_LEDS 32
#define BRIGHTNESS 64
CRGBArray<NUM_LEDS> leds;
This file has been truncated. show original
//***************************************************************
// Marquee fun (v3)
// Pixel position down the strip comes from this formula:
// pos = spacing * (i-1) + spacing
// i starts at 0 and is incremented by +1 up to NUM_LEDS/spacing.
//
// Marc Miller, May 2016
// Updated June 2018 - reordered some stuff and small bug fix.
//***************************************************************
#include "FastLED.h"
#define LED_TYPE LPD8806
#define NUM_LEDS 32
#define COLOR_ORDER GRB
//#define LED_TYPE APA102
//#define NUM_LEDS 39
//#define COLOR_ORDER BGR
#define DATA_PIN 11
This file has been truncated. show original
@Sam_Guyer I’m not sure. I was using that because it simulated the effect I’m looking for. I’ll see if I still want or need it after I get the original idea working.
@marmil Thanks, Marc! I think I can figure it out from those examples.
I haven’t tested this, but heres how I think I would’ve done it:
#include <FastLED.h>
#define NUM_LEDS 150
#define DATA_PIN 6
#define GLOBAL_BRIGHTNESS 150
const uint16_t update_delay = 10;
int last_update = 0;
uint8_t index = 0;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setCorrection( TypicalSMD5050 );
FastLED.setBrightness(GLOBAL_BRIGHTNESS);
FastLED.setTemperature(UncorrectedTemperature);
}
void loop() {
//Check if enough time has elapsed since last update
This file has been truncated. show original