FastLED 3.9.15
Loading...
Searching...
No Matches
FxNoiseRing.ino

This sketch is fully compatible with the FastLED web compiler.

This sketch is fully compatible with the FastLED web compiler. To use it do the following:

  1. Install Fastled: pip install fastled
  2. cd into this examples page.
  3. Run the FastLED web compiler at root: fastled
  4. When the compiler is done a web page will open.
// @filter: (memory is large)
// PCH-compatible include order: Arduino.h and FastLED.h must come first
#include <Arduino.h>
#include "FastLED.h"
// Now we can include other headers and do platform checks
#include "fl/stl/json.h"
#include "fl/math/math.h"
#include "fl/math/math.h"
#include "fl/log/log.h"
#include "noisegen.h"
#include "fl/stl/span.h"
#include "fl/ui/ui.h"
#include "fl/sensors/pir.h"
#include "fl/stl/sstream.h"
#include "fl/stl/assert.h"
// Defines come after all includes
#ifndef DATA_PIN
#define DATA_PIN 3
#endif // DATA_PIN
#define COLOR_ORDER GRB // Color order matters for a real device, web-compiler will ignore this.
#define NUM_LEDS 250
#define PIN_PIR 0
#define PIR_LATCH_MS 60000 // how long to keep the PIR sensor active after a trigger
#define PIR_RISING_TIME 1000 // how long to fade in the PIR sensor
#define PIR_FALLING_TIME 1000 // how long to fade out the PIR sensor
// These sliders and checkboxes are dynamic when using the FastLED web compiler.
// When deployed to a real device these elements will always be the default value.
fl::UISlider brightness("Brightness", 1, 0, 1);
fl::UISlider scale("Scale", 4, .1, 4, .1);
fl::UISlider timeBitshift("Time Bitshift", 5, 0, 16, 1);
fl::UISlider timescale("Time Scale", 1, .1, 10, .1);
// This PIR type is special because it will bind to a pin for a real device,
// but also provides a UIButton when run in the simulator.
fl::UICheckbox useDither("Use Binary Dither", true);
// Save a pointer to the controller so that we can modify the dither in real time.
void setup() {
Serial.begin(115200);
// ScreenMap is purely something that is needed for the sketch to correctly
// show on the web display. For deployements to real devices, this essentially
// becomes a no-op.
.setCorrection(TypicalLEDStrip)
.setDither(DISABLE_DITHER)
.setScreenMap(xyMap);
FastLED.setBrightness(brightness);
pir.activate(fl::millis()); // Activate the PIR sensor on startup.
}
void draw(uint32_t now) {
double angle_offset = double(now) / 32000.0 * 2 * FL_M_PI;
now = (now << timeBitshift.as<int>()) * timescale.as<double>();
// get radius/zoom level from slider
float noise_radius = scale.as<float>();
// go in circular formation and set the leds
for (int i = 0; i < NUM_LEDS; i++) {
float angle = i * 2 * FL_M_PI / NUM_LEDS + angle_offset;
// Use the new noiseRingHSV8 function to sample three z-slices for HSV components
CHSV hsv = fl::noiseRingHSV8(angle, now, noise_radius);
// Apply same constraints as before: minimum saturation and adjusted value
hsv.s = fl::max(128u, (unsigned)hsv.s);
// Apply value mapping similar to original: map from 0-255 to -64-255, clamp to 0-255
uint16_t val = hsv.v;
int16_t adjusted_val = map(val, 0, 255, -64, 255);
if (adjusted_val < 0) {
adjusted_val = 0;
}
hsv.v = adjusted_val;
leds[i] = hsv;
}
}
void loop() {
// Allow the dither to be enabled and disabled.
uint8_t bri = pir.transition(now);
FastLED.setBrightness(bri * brightness.as<float>());
// Apply leds generation to the leds.
draw(now);
FastLED.show();
}
void setup()
void loop()
#define COLOR_ORDER
fl::XYMap xyMap
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
#define DATA_PIN
Definition ClientReal.h:82
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::UICheckbox useDither("Use Binary Dither", true)
#define PIR_FALLING_TIME
#define PIN_PIR
CLEDController * controller
#define PIR_LATCH_MS
fl::UISlider timeBitshift("Time Bitshift", 5, 0, 16, 1)
float current_brightness
fl::Pir pir(PIN_PIR, PIR_LATCH_MS, PIR_RISING_TIME, PIR_FALLING_TIME)
fl::UISlider timescale("Time Scale", 1,.1, 10,.1)
fl::UISlider scale("Scale", 4,.1, 4,.1)
#define PIR_RISING_TIME
Definition pir.h:38
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f, float completion=1.0f) FL_NOEXCEPT
fl::CLEDController CLEDController
void draw(float pos)
Definition curr.h:526
#define BINARY_DITHER
Enable dithering using binary dithering (only option)
Definition dither_mode.h:12
#define DISABLE_DITHER
Disable dithering.
Definition dither_mode.h:10
Functions to generate noise patterns on rings and spheres.
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
fl::hsv8 CHSV
Definition chsv.h:11
CHSV noiseRingHSV8(float angle, u32 time, float radius)
Generate HSV8 (8-bit) noise for a ring pattern.
Definition noise.cpp.hpp:51
FastLED's Elegant JSON Library: fl::json
Centralized logging categories for FastLED hardware interfaces and subsystems.
#define FL_M_PI
Definition math.h:34
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
unsigned char uint8_t
Definition s16x16x4.h:209
Noise generation classes.
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
#define Serial
Definition serial.h:304
Aggregator header for the fl/ui/ family of per-element UI types.