Skip to content

Instantly share code, notes, and snippets.

@ASteinheiser
Created September 29, 2018 00:33
Show Gist options
  • Save ASteinheiser/c4136057270013fc52522a36cb3149ee to your computer and use it in GitHub Desktop.
Save ASteinheiser/c4136057270013fc52522a36cb3149ee to your computer and use it in GitHub Desktop.
FastLED running on a Particle Photon powering a strip of NeoPixels.
// This #include statement was automatically added by the Particle IDE.
#include <FastLED.h>
FASTLED_USING_NAMESPACE;
#define LED_PIN D2
#define CHIPSET NEOPIXEL
#define NUM_LEDS 144
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
uint8_t x[NUM_LEDS];
uint8_t y[NUM_LEDS];
void setup()
{
FastLED.addLeds<CHIPSET, LED_PIN>(leds, NUM_LEDS);
LEDS.setBrightness(BRIGHTNESS);
for (uint16_t i = 0; i < NUM_LEDS; i++) { // precalculate the lookup-tables:
uint8_t angle = (i * 256) / NUM_LEDS; // on which position on the circle is the led?
x[i] = cos8( angle ); // corrsponding x position in the matrix
y[i] = sin8( angle ); // corrsponding y position in the matrix
}
}
void loop()
{
for (uint16_t i = 0; i < 5000; i++) {
color_flow();
FastLED.show();
}
Particle.process();
}
// moves a noise up and down while slowly shifting to the side
void color_flow() {
uint8_t scale = 232; // the "zoom factor" for the noise
for (uint16_t i = 0; i < NUM_LEDS; i++) {
uint16_t shift_x = beatsin8(17); // the x position of the noise field swings @ 17 bpm
uint16_t shift_y = millis() / 100; // the y position becomes slowly incremented
uint32_t real_x = (x[i] + shift_x) * scale; // calculate the coordinates within the noise field
uint32_t real_y = (y[i] + shift_y) * scale; // based on the precalculated positions
uint8_t noise = inoise16(real_x, real_y, 4223) >> 8; // get the noise data and scale it down
uint8_t index = noise * 3; // map led color based on noise data
uint8_t bri = noise;
CRGB color = CHSV( index, 255, bri);
leds[i] = color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment