Skip to content

Instantly share code, notes, and snippets.

@atuline
Last active February 16, 2022 14:12
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/a5a66cac8ebbd7ac7496731465410b8d to your computer and use it in GitHub Desktop.
Save atuline/a5a66cac8ebbd7ac7496731465410b8d to your computer and use it in GitHub Desktop.
Circular loader ring
/* Circular loader ring (a real basic one)
*
* By: Andrew Tuline
*
* Date: May, 2019
*
* One version uses a loop and fixed colours, while the other uses a fader.
*
*/
#include "FastLED.h" // FastLED library.
// Fixed definitions cannot change on the fly.
#define LED_DT D5 // Data pin to connect to the strip.
#define COLOR_ORDER GRB // It's GRB for WS2812 and BGR for APA102.
#define LED_TYPE WS2812 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit.
#define NUM_LEDS 40 // Number of LED's.
// Global variables can be changed on the fly.
uint8_t max_bright = 128; // Overall brightness.
struct CRGB leds[NUM_LEDS]; // Initialize our LED array.
void setup() {
Serial.begin(115200); // Initialize serial port for debugging.
delay(1000); // Soft startup to ease the flow of electrons.
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // Use this for WS2812
FastLED.setBrightness(max_bright);
} // setup()
void loop () {
circring();
// fadering(); // Use one or the other.
FastLED.show();
} // loop()
void circring() {
memset(leds, 0, NUM_LEDS * 3); // Clear the strand
uint8_t mytime = (millis() / 50) % NUM_LEDS;
uint8_t mylen = beatsin8(12,1,NUM_LEDS/3);
for (uint8_t i = 0; i < mylen; i++) { // We can't do a fill_solid as we need to use a modulus operator to wrap around the strand.
leds[(mytime + i)%NUM_LEDS] = CHSV(0,255,255);
}
} // circring()
void fadering() { // Non-looped version using a fader.
uint8_t fadeval = beatsin8(12,2,20);
fadeToBlackBy(leds, NUM_LEDS, fadeval);
leds[millis()/20%NUM_LEDS] = CHSV(0,255,255);
} // fadering()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment