Skip to content

Instantly share code, notes, and snippets.

@joshua-8
Created May 16, 2022 21:02
Show Gist options
  • Save joshua-8/2eda6c30046049c454fd09e8f9b77460 to your computer and use it in GitHub Desktop.
Save joshua-8/2eda6c30046049c454fd09e8f9b77460 to your computer and use it in GitHub Desktop.
/**
Arduino program written by joshua-8 and rowanberry in 2021
This program was written to display patterns on
Adafruit's large led disk: https://www.adafruit.com/product/2477
a "sector", a portion of one of the circular paths, can be light up and fade out towards each end
another animation looks like a stone dropped in the center of poo.
*/
#include <FastLED.h>
#define NUM_LEDS 255
#define NUM_RINGS 10
//red and black
#define DATA_PIN 54 //green
#define CLOCK_PIN 55 //yellow
CRGB leds[NUM_LEDS];
void setup() {
delay(2000);
FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
FastLED.show();
}
void loop() {
for (int i = 0; i < NUM_LEDS; i++) { //reset all lights to black, the sector functions don't do that so patterns can be displayed under them.
leds[i] = CRGB::Black;
}
dropRipple(millis() - 3000, 4000, 500, 190, 255, 255, 3, 255 * 3 / 10);
// lightSector(leds, millis(), 2000, 0, 48, 200, 200, 200, 200);
// lightSector(leds, millis(), 2000, 48, 44, 200, 200, 200, 100);
FastLED.show();
}
void dropRipple(long t, long timeRange, long drop, byte hue, byte sat, byte maxBright, byte numRipples, int space) {
if (t >= 0 && t <= timeRange) {
if (t < drop) {
ripple(120 - t * 150 / drop, hue, sat, map(t, 0, drop, 0, maxBright), 255 * 3);
} else {
for (byte i = 0; i < numRipples; i++) {
ripple((t - drop) * (255 + space * (numRipples - 1)) / (timeRange - drop) - space * i, hue, sat, map(t, drop, timeRange, maxBright, 0), 255 * 3);
}
}
}
}
void ripple(long val, byte hue, byte sat, byte maxBright, int width) {
//val: 0-255, makes moving ring
val = val * (255 * (NUM_RINGS) + width / 2) / 255 - width / 2;
for (int i = 0; i < 10; i++) {
if (abs(val - i * 255) <= width / 2) {
lightRingSet(leds, i, CHSV(hue, sat, map(abs(val - i * 255), 0, width / 2, maxBright, 0)));
}
}
}
void lightSector(struct CRGB * ledArray, long val, long valCycle, int firstLight, int numLights, byte hue, byte sat, byte maxBright, int sector) {
//the CRGB array to write into, wheel rotation, full circle rotation units, index of light circle starts at, number of lights in circle, hue, sat, max brightness, portion of valCycle that gets lit
for (int i = firstLight; i < firstLight + numLights; i++) {
int dist = abs(mmod(val - (long)(i - firstLight) * valCycle / numLights, valCycle) - valCycle / 2);
if (dist <= sector / 2) {
ledArray[i] = CHSV(hue, sat, map(dist, 0, sector / 2, maxBright, 0));
}
}
}
void lightRingSet(struct CRGB * ledArray, int n, CRGB color) {
//sets a whole ring a color
if (n >= 0 && n < 10) {
byte first[] = {254, 248, 236, 216, 192, 164, 132, 92, 48, 0};
byte last[] = {254, 253, 247, 235, 215, 191, 163, 131, 91, 47};
for (int i = first[n]; i <= last[n]; i++) {
ledArray[i] = color;
}
}
}
int mmod(long x, int m) {
//always positive version of modulo
return ((x % m) + m) % m;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment