Skip to content

Instantly share code, notes, and snippets.

@fedorg
Created September 14, 2024 22:10
Show Gist options
  • Save fedorg/2029ba51e879811127ec3aa8a4f429c6 to your computer and use it in GitHub Desktop.
Save fedorg/2029ba51e879811127ec3aa8a4f429c6 to your computer and use it in GitHub Desktop.
#include <FastLED.h>
#define LED_PIN 13
#define LED_BUILTIN 2
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 180 // Popular NeoPixel ring size
#define DELAYVAL 10 // Time (in milliseconds) to pause between frames
CRGB leds[NUMPIXELS];
int iter_id = 0;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
delay(100);
pinMode(LED_BUILTIN, OUTPUT);
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUMPIXELS);
}
void fill_rainbow( struct CRGB * pFirstLED, int numToFill,
float initialhue,
float deltahue, uint8_t val, uint8_t sat)
{
float hueshift = 0.00f;
CHSV hsv;
hsv.hue = initialhue;
hsv.val = val;
hsv.sat = sat;
for( int i = 0; i < numToFill; ++i) {
pFirstLED[i] = hsv;
hueshift += deltahue;
hsv.hue = initialhue + hueshift;
}
}
// led modes
void rainbow() {
auto maxhueshift = 10;
float initial = 240+27;
auto deltahue = 0.02;
auto value = 60;
auto saturation = 240;
static float i = 1;
static float direction = 0.0; //0.005;
// static float direction = 0.005;
i += direction;
// float jitter = random(0,255)/255.0 * 0.1;
auto jitter = 0;
if (i > maxhueshift) {direction = -direction;}
if (i < 1) {direction = -direction;}
fill_rainbow(leds, NUMPIXELS, initial + (i + jitter), deltahue, value, saturation);
// CHSV hsv{ hue, 255, 255 };
// CRGB rgb;
// hsv2rgb_rainbow(hsv, rgb);
// FastLED.showColor(rgb);
FastLED.show();
}
void loop() {
iter_id++;
// digitalWrite(LED_BUILTIN, iter_id % 2);
digitalWrite(LED_BUILTIN, HIGH);
rainbow();
delay(DELAYVAL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment