FastLED 3.9.3
Loading...
Searching...
No Matches
NoiseRing.ino
1
2
7
8#include <Arduino.h>
9
10#include <stdio.h>
11
12#include "json.h"
13#include "math_macros.h"
14#include "noisegen.h"
15#include "screenmap.h"
16#include "slice.h"
17#include "ui.h"
18#include "FastLED.h"
19#include "pir.h"
20#include "timer.h"
21
22#define LED_PIN 2
23#define BRIGHTNESS 96
24#define COLOR_ORDER GRB
25#define NUM_LEDS 250
26#define PIN_PIR 0
27
28CRGB leds[NUM_LEDS];
29
30Slider brightness("Brightness", 255, 0, 255);
31Slider scale("Scale", 4, .1, 4, .1);
32Slider timeBitshift("Time Bitshift", 5, 0, 16, 1);
33Slider timescale("Time Scale", 1, .1, 10, .1);
34Pir pir(PIN_PIR);
35
36Timer timer;
37float current_brightness = 0;
38bool first = true;
39
40uint8_t update_brightness(bool clicked, uint32_t now) {
41 if (clicked) {
42 timer.start(millis(), 1000 * 60 * 3);
43 }
44 if (timer.update(now)) {
45 current_brightness += .6;
46 } else {
47 current_brightness *= .97;
48 }
49 uint32_t brightness = current_brightness;
50 if (brightness > 255) {
51 brightness = 255;
52 }
53 return brightness;
54}
55
56
57void setup() {
58 ScreenMap xyMap = ScreenMap::Circle(NUM_LEDS, 2.0, 2.0);
59 FastLED.addLeds<WS2811, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
60 .setCorrection(TypicalLEDStrip)
61 .setScreenMap(xyMap);
62 FastLED.setBrightness(brightness);
63}
64
65void loop() {
66 const bool detectMotion = pir.detect();
67 const bool detected_motion = detectMotion || first || detectMotion;
68 first = false;
69 uint8_t bri = update_brightness(detected_motion, millis());
71 uint32_t now = millis();
72 double angle_offset = double(now) / 32000.0 * 2 * M_PI;
73 //angle_offset = 0;
74 now = (now << timeBitshift.as<int>()) * timescale.as<double>();
75 // inoise8(x + ioffset,y + joffset,z);
76 // go in circular formation and set the leds
77 for (int i = 0; i < NUM_LEDS; i++) {
78 float angle = i * 2 * M_PI / NUM_LEDS + angle_offset;
79 float x = cos(angle);
80 float y = sin(angle);
81 x *= 0xffff * scale.as<double>();
82 y *= 0xffff * scale.as<double>();
83 uint16_t noise = inoise16(x, y, now);
84 uint16_t noise2 = inoise16(x, y, 0xfff + now);
85 uint16_t noise3 = inoise16(x, y, 0xffff + now);
86 noise3 = noise3 >> 8;
87 int16_t noise4 = map(noise3, 0, 255, -64, 255);
88 if (noise4 < 0) {
89 noise4 = 0;
90 }
91
92 leds[i] = CHSV(noise >> 8, MAX(128, noise2 >> 8), noise4);
93 // std::swap(leds[i].b, leds[i].g);
94 }
95 FastLED.show();
96}
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:33
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:722
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:82
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:67
Definition pir.h:8
Definition ui.h:40
Definition timer.h:5
WS2811 controller class.
Definition FastLED.h:233
@ 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
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:11
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39