FastLED 3.9.7
Loading...
Searching...
No Matches
NoiseRing.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 "noisegen.h"
20#include "fl/screenmap.h"
21#include "fl/slice.h"
22#include "fl/ui.h"
23#include "FastLED.h"
24#include "sensors/pir.h"
25#include "timer.h"
26#include <iostream>
27
28#define LED_PIN 1
29#define BRIGHTNESS 96
30#define COLOR_ORDER GRB
31#define NUM_LEDS 250
32#define PIN_PIR 0
33
34#define PIR_LATCH_MS 60000 // how long to keep the PIR sensor active after a trigger
35#define PIR_RISING_TIME 1000 // how long to fade in the PIR sensor
36#define PIR_FALLING_TIME 1000 // how long to fade out the PIR sensor
37
38using namespace fl;
39
40CRGB leds[NUM_LEDS];
41
42Slider brightness("Brightness", 1, 0, 1);
43Slider scale("Scale", 4, .1, 4, .1);
44Slider timeBitshift("Time Bitshift", 5, 0, 16, 1);
45Slider timescale("Time Scale", 1, .1, 10, .1);
46PirAdvanced pir(PIN_PIR, PIR_LATCH_MS, PIR_RISING_TIME, PIR_FALLING_TIME);
47
48Timer timer;
49float current_brightness = 0;
50
51
52void setup() {
53 Serial.begin(115200);
54 ScreenMap xyMap = ScreenMap::Circle(NUM_LEDS, 2.0, 2.0);
55 FastLED.addLeds<WS2811, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
56 .setCorrection(TypicalLEDStrip)
57 .setScreenMap(xyMap);
58 FastLED.setBrightness(brightness);
59 pir.activate(millis()); // Activate the PIR sensor on startup.
60}
61
62void loop() {
64 // printf("FPS: %d\n", FastLED.getFPS());
65 std::cout << "loop" << std::endl;
66 }
67 uint8_t bri = pir.transition(millis());
68 FastLED.setBrightness(bri * brightness.as<float>());
69 uint32_t now = millis();
70 double angle_offset = double(now) / 32000.0 * 2 * M_PI;
71 //angle_offset = 0;
72 now = (now << timeBitshift.as<int>()) * timescale.as<double>();
73 // inoise8(x + ioffset,y + joffset,z);
74 // go in circular formation and set the leds
75 for (int i = 0; i < NUM_LEDS; i++) {
76 float angle = i * 2 * M_PI / NUM_LEDS + angle_offset;
77 float x = cos(angle);
78 float y = sin(angle);
79 x *= 0xffff * scale.as<double>();
80 y *= 0xffff * scale.as<double>();
81 uint16_t noise = inoise16(x, y, now);
82 uint16_t noise2 = inoise16(x, y, 0xfff + now);
83 uint16_t noise3 = inoise16(x, y, 0xffff + now);
84 noise3 = noise3 >> 8;
85 int16_t noise4 = map(noise3, 0, 255, -64, 255);
86 if (noise4 < 0) {
87 noise4 = 0;
88 }
89
90 leds[i] = CHSV(noise >> 8, MAX(128, noise2 >> 8), noise4);
91 // std::swap(leds[i].b, leds[i].g);
92 }
93 FastLED.show();
94}
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:45
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:723
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:94
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:79
Definition timer.h:5
WS2811 controller class.
Definition FastLED.h:234
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z)
16-bit, fixed point implementation of Perlin's noise.
Definition noise.cpp:378
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1283
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