Skip to content

Instantly share code, notes, and snippets.

@atuline
Last active September 29, 2022 21:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atuline/47b5700a44af072bb29d756cd347cebe to your computer and use it in GitHub Desktop.
Save atuline/47b5700a44af072bb29d756cd347cebe to your computer and use it in GitHub Desktop.
/* simplemover
*
* By: A simple routine to move every 4th LED up the strip and fade behind.
*
* No delay statements were harmed in the creation of this routine.
*
* By: Andrew Tuline
*
* Date: June 11, 2018
*
*/
#include "FastLED.h" // FastLED library.
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define LED_DT 12 // Data pin to connect to the strip.
#define LED_CK 11 // Clock pin for WS2801 or APA102.
#define COLOR_ORDER BGR // It's GRB for WS2812 and BGR for APA102.
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to change LEDS.addLeds.
#define NUM_LEDS 16 // Number of LED's.
// Global variables can be changed on the fly.
uint8_t max_bright = 255; // Overall brightness definition. It can be changed on the fly.
CRGB leds[NUM_LEDS];
void setup() {
delay(1000); // Power-up safety delay.
Serial.begin(57600); // Initialize serial port for debugging.
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2801 or APA102
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812
FastLED.setBrightness(max_bright);
set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA.
} // setup()
void loop() {
simplemover();
FastLED.show();
} // loop()
void simplemover() {
int speedval = 100; // Higher = slower speed.
uint8_t faderate = 2; // Higher = quicker fade.
fadeToBlackBy(leds, NUM_LEDS, faderate); // 8 bit, 1 = slow, 255 = fast. You will need to adjust the fade based on the length of your strip
for (int i = 0; i<NUM_LEDS; i=i+4) { // Turn on every 4th LED up to NUM_LEDS
leds[(millis()/speedval+i) % NUM_LEDS] = CRGB::White; // Use millis() to count up.
}
} // simplemover()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment