FastLED 3.9.15
Loading...
Searching...
No Matches
FxNoiseRing.ino
Go to the documentation of this file.
1
2
12
13#include <Arduino.h>
14
15#include <stdio.h>
16
17#include "fl/json.h"
18#include "fl/math_macros.h"
19#include "fl/warn.h"
20#include "noisegen.h"
21#include "fl/screenmap.h"
22#include "fl/slice.h"
23#include "fl/ui.h"
24#include "FastLED.h"
25#include "sensors/pir.h"
26#include "timer.h"
27
28#define LED_PIN 2
29#define COLOR_ORDER GRB
30#define NUM_LEDS 250
31#define PIN_PIR 0
32
33#define PIR_LATCH_MS 60000 // how long to keep the PIR sensor active after a trigger
34#define PIR_RISING_TIME 1000 // how long to fade in the PIR sensor
35#define PIR_FALLING_TIME 1000 // how long to fade out the PIR sensor
36
37using namespace fl;
38
40
41UISlider brightness("Brightness", 1, 0, 1);
42UISlider scale("Scale", 4, .1, 4, .1);
43UISlider timeBitshift("Time Bitshift", 5, 0, 16, 1);
44UISlider timescale("Time Scale", 1, .1, 10, .1);
46UICheckbox useDither("Use Binary Dither", true);
47
50
52
53
54void setup() {
55 Serial.begin(115200);
58 .setCorrection(TypicalLEDStrip)
59 .setDither(DISABLE_DITHER)
60 .setScreenMap(xyMap);
61 FastLED.setBrightness(brightness);
62 pir.activate(millis()); // Activate the PIR sensor on startup.
63}
64
65void draw(uint32_t now) {
66 double angle_offset = double(now) / 32000.0 * 2 * M_PI;
67 now = (now << timeBitshift.as<int>()) * timescale.as<double>();
68 // go in circular formation and set the leds
69 for (int i = 0; i < NUM_LEDS; i++) {
70 float angle = i * 2 * M_PI / NUM_LEDS + angle_offset;
71 float x = cos(angle);
72 float y = sin(angle);
73 x *= 0xffff * scale.as<double>();
74 y *= 0xffff * scale.as<double>();
75 uint16_t noise = inoise16(x, y, now);
76 uint16_t noise2 = inoise16(x, y, 0xfff + now);
77 uint16_t noise3 = inoise16(x, y, 0xffff + now);
78 noise3 = noise3 >> 8;
79 int16_t noise4 = map(noise3, 0, 255, -64, 255);
80 if (noise4 < 0) {
81 noise4 = 0;
82 }
83 leds[i] = CHSV(noise >> 8, MAX(128, noise2 >> 8), noise4);
84 }
85}
86
87void loop() {
88
91 FASTLED_WARN("loop");
92 }
93 uint8_t bri = pir.transition(millis());
94 FastLED.setBrightness(bri * brightness.as<float>());
95 draw(millis());
96 FastLED.show();
97}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
XYMap xyMap(WIDTH, HEIGHT, false)
UISlider scale("Scale", 1.0f, 0.0f, 1.0f, 0.01f)
#define COLOR_ORDER
#define LED_PIN
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:58
central include file for FastLED, defines the CFastLED class/object
uint8_t noise[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.ino:88
uint8_t noise2[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.ino:89
UISlider brightness("Brightness", 255, 0, 255, 1)
UISlider scale("Scale", 4,.1, 4,.1)
#define PIR_FALLING_TIME
void setup()
PirAdvanced pir(PIN_PIR, PIR_LATCH_MS, PIR_RISING_TIME, PIR_FALLING_TIME)
UISlider timescale("Time Scale", 1,.1, 10,.1)
#define PIN_PIR
CLEDController * controller
void draw(uint32_t now)
#define PIR_LATCH_MS
UISlider timeBitshift("Time Bitshift", 5, 0, 16, 1)
float current_brightness
Timer timer
UICheckbox useDither("Use Binary Dither", true)
#define PIR_RISING_TIME
UISlider brightness("Brightness", 1, 0, 1)
void loop()
Base definition for an LED controller.
Definition timer.h:5
WS2811 controller class.
Definition FastLED.h:258
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f, float completion=1.0f)
Definition screenmap.cpp:21
#define BINARY_DITHER
Enable dithering using binary dithering (only option)
Definition dither_mode.h:13
#define DISABLE_DITHER
Disable dithering.
Definition dither_mode.h:11
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z, uint32_t t)
16-bit, fixed point implementation of Perlin's noise.
Definition noise.cpp:440
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1306
#define M_PI
Definition math_macros.h:61
#define MAX(a, b)
Definition math_macros.h:11
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Noise generation classes.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55
#define FASTLED_WARN
Definition warn.h:7