Skip to content

Instantly share code, notes, and snippets.

@hsiboy
Last active January 29, 2016 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsiboy/6169dd474c37abd42701 to your computer and use it in GitHub Desktop.
Save hsiboy/6169dd474c37abd42701 to your computer and use it in GitHub Desktop.
//***************************************************************
// repeating_pattern.ino
// Marc Miller, Nov 2015
//
// If we want a pattern to repeat every 5 pixels then the
// first pixel set to light up would be: 0,5,10,15,20...
// This can be represented by: leds[5*(x-1) + 5]
//***************************************************************
#include "FastLED.h"
#define LED_TYPE WS2811
#define DATA_PIN 6
#define NUM_LEDS 60
#define COLOR_ORDER GRB
#define MASTER_BRIGHTNESS 100
CRGB leds[NUM_LEDS];
uint8_t hue; // Pixel color
uint8_t offset; // To keep track of the offset in the pattern
uint16_t i; // A pixel position on the strip
// How often does the pattern repeat? Change as needed.
static uint16_t repeatEvery = 5;
// Therefore the number of times the pattern will repeat down the strip is:
static uint16_t numberOfRepeats = NUM_LEDS/repeatEvery;
void setup() {
delay(3000); // Delay to make sure serial monitor is ready.
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(MASTER_BRIGHTNESS);
FastLED.clear();
FastLED.show();
}
void loop() {
for (offset = 0; offset < repeatEvery; offset++) { // Operate on each repeating pixel set
hue = (255/repeatEvery) * offset; // Change the hue for each pixel set.
for (uint16_t x = 0; x < numberOfRepeats+1; x++) {
i = (repeatEvery*(x-1)) + repeatEvery + offset; // The pixel number to draw
if (i < NUM_LEDS) { // Only draw pixel numbers within NUM_LEDS
leds[i] = CHSV(hue,180,255);
FastLED.show(); // Display each pixel individually in a set
delay(100);
}
} //end of loop for pixel set
// Uncomment the show() below and comment out the show() above to
// have all the pixels in a set display at the same time.
//FastLED.show(); // Display all pixels in a set at the same time.
delay(800); // Pause before lighting next pixel set
} //end offset loop
delay(1000); // pause before clearing
FastLED.clear(); // clear the strip
FastLED.delay(1400); // pause before starting over
} //END MAIN LOOP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment