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
54 if (Serial.available()) {
55 char input = Serial.read();
56 if (input == '0') {
57 useDither = false;
58 } else if (input == '1') {
59 useDither = true;
60 } else {
61 FASTLED_WARN("Invalid dither input. Use 0 or 1");
62 }
63 }
64}
65
66void setup() {
67 Serial.begin(115200);
70 .setCorrection(TypicalLEDStrip)
71 .setDither(DISABLE_DITHER)
72 .setScreenMap(xyMap);
73 FastLED.setBrightness(brightness);
74 pir.activate(millis()); // Activate the PIR sensor on startup.
75}
76
77void draw(uint32_t now) {
78 double angle_offset = double(now) / 32000.0 * 2 * M_PI;
79 now = (now << timeBitshift.as<int>()) * timescale.as<double>();
80 // go in circular formation and set the leds
81 for (int i = 0; i < NUM_LEDS; i++) {
82 float angle = i * 2 * M_PI / NUM_LEDS + angle_offset;
83 float x = cos(angle);
84 float y = sin(angle);
85 x *= 0xffff * scale.as<double>();
86 y *= 0xffff * scale.as<double>();
87 uint16_t noise = inoise16(x, y, now);
88 uint16_t noise2 = inoise16(x, y, 0xfff + now);
89 uint16_t noise3 = inoise16(x, y, 0xffff + now);
90 noise3 = noise3 >> 8;
91 int16_t noise4 = map(noise3, 0, 255, -64, 255);
92 if (noise4 < 0) {
93 noise4 = 0;
94 }
95 leds[i] = CHSV(noise >> 8, MAX(128, noise2 >> 8), noise4);
96 }
97}
98
99void loop() {
100 handleSerialDither(); // Add this line at start of loop()
101
103 EVERY_N_SECONDS(1) {
104 FASTLED_WARN("loop");
105 }
106 uint8_t bri = pir.transition(millis());
107 FastLED.setBrightness(bri * brightness.as<float>());
108 draw(millis());
109 FastLED.show();
110}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
#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:86
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint8_t noise2[NUM_LAYERS][WIDTH][HEIGHT]
Definition Fire2023.ino:87
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
XYMap xyMap(HEIGHT, WIDTH, SERPENTINE)
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)
void handleSerialDither()
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:241
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f)
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
#define MAX(a, b)
Definition math_macros.h:4
@ 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:466
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1324
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:54
#define FASTLED_WARN
Definition warn.h:7