FastLED 3.9.15
Loading...
Searching...
No Matches
FestivalStick.ino
Go to the documentation of this file.
1/*
2Festival Stick is a dense corkscrew of LEDs that is wrapped around one end of
3a wooden walking stick commonly found on amazon.A0
4
5The UI screenmap projects this cork screw into polar coordinates, so that the LEDs are
6mapped to a sprial, with the inner portion of the spiral being the top, the outer
7most portion being the bottom.
8
9*/
10
11
12
13#include "fl/assert.h"
14#include "fl/screenmap.h"
15#include "fl/warn.h"
16#include "noise.h"
17#include <FastLED.h>
18// #include "vec3.h"
19
20using namespace fl;
21
22
23#define PIN_DATA 9
24#define PIN_CLOCK 7
25
26#define NUM_LEDS 288
27// #define CM_BETWEEN_LEDS 1.0 // 1cm between LEDs
28// #define CM_LED_DIAMETER 0.5 // 0.5cm LED diameter
29
30UITitle festivalStickTitle("Festival Stick");
32 "Take a wooden walking stick, wrap dense LEDs around it like a corkscrew. Super simple but very awesome looking."
33 "This assumes the dense 144 LEDs / meter.");
34
35
36
37UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f);
38
39
41
42
43// fl::vector<vec3f>
46 float leds_per_turn = 15.5;
47 float width_cm = 1.0;
48};
49
51 // int num_leds, float leds_per_turn, float width_cm
52 int num_leds = args.num_leds;
53 float leds_per_turn = args.leds_per_turn;
54 float width_cm = args.width_cm;
55
56 const float circumference = leds_per_turn;
57 const float radius = circumference / (2.0 * PI); // radius in mm
58 const float angle_per_led = 2.0 * PI / leds_per_turn; // degrees per LED
59 const float total_angle_radians = angle_per_led * num_leds;
60 const float total_turns = total_angle_radians / (2.0 * PI); // total turns
61 const float height_per_turn_cm = width_cm; // 10cm height per turn
62 const float height_per_led =
63 height_per_turn_cm /
64 leds_per_turn; // this is the changing height per led.
65 const float total_height =
66 height_per_turn_cm * total_turns; // total height of the corkscrew
68 for (int i = 0; i < num_leds; i++) {
69 float angle = i * angle_per_led; // angle in radians
70 float height = (i / leds_per_turn) * height_per_turn_cm; // height in cm
71
72 // Calculate the x, y, z coordinates for the corkscrew
73 float x = radius * cos(angle); // x coordinate
74 float z = radius * sin(angle); // y coordinate
75 float y = height; // z coordinate
76
77 // Store the 3D coordinates in the vector
78 vec3f led_position(x, y, z);
79 // screenMap.set(i, led_position);
80 out.push_back(led_position);
81 }
82 return out;
83}
84
85
87 // Create a ScreenMap for the corkscrew
88 fl::vector<vec2f> points(args.num_leds);
89
90 int num_leds = args.num_leds;
91 float leds_per_turn = args.leds_per_turn;
92 float width_cm = args.width_cm;
93
94
95 const float circumference = leds_per_turn;
96 const float radius = circumference / (2.0 * PI); // radius in mm
97 const float angle_per_led = 2.0 * PI / leds_per_turn; // degrees per LED
98 const float height_per_turn_cm = width_cm; // 10cm height per turn
99 const float height_per_led =
100 height_per_turn_cm /
101 leds_per_turn * 1.3; // this is the changing height per led.
102
103
104
105 for (int i = 0; i < num_leds; i++) {
106 float angle = i * angle_per_led; // angle in radians
107 float r = radius + 10 + i * height_per_led; // height in cm
108
109 // Calculate the x, y coordinates for the corkscrew
110 float x = r * cos(angle); // x coordinate
111 float y = r * sin(angle); // y coordinate
112
113 // Store the 2D coordinates in the vector
114 points[i] = vec2f(x, y);
115 }
116
117 FASTLED_WARN("Creating ScreenMap with:\n" << points);
118
119 // Create a ScreenMap from the points
120 fl::ScreenMap screenMap(points.data(), num_leds, 1.0);
121 return screenMap;
122}
123
124
125// Create a corkscrew with:
126// - 30cm total length (300mm)
127// - 5cm width (50mm)
128// - 2mm LED inner diameter
129// - 24 LEDs per turn
130// fl::ScreenMap screenMap = makeCorkScrew(NUM_LEDS,
131// 300.0f, 50.0f, 2.0f, 24.0f);
132
136
137
142
143
144void setup() {
146 //screenMap = ScreenMap::Circle(NUM_LEDS, 1.5f, 0.5f, 1.0f);
147 auto controller = addController();
148 // Set the screen map for the controller
149 controller->setScreenMap(screenMap);
150 FastLED.setBrightness(32);
151}
152
153// extern uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z, uint32_t t);
154
155
157 // This function is called to show the generative pattern
158 uint32_t now = millis();
160
161 for (int i = 0; i < NUM_LEDS; i++) {
162 // Get the 2D position of this LED from the screen map
164 float x = pos.x;
165 float y = pos.y;
166 float z = pos.z;
167
168 x*= 20.0f * ledsScale.value();
169 y*= 20.0f * ledsScale.value();
170 z*= 20.0f * ledsScale.value();
171
172 uint16_t noise_value = inoise16(x,y,z, now / 100);
173 // Normalize the noise value to 0-255
174 uint8_t brightness = map(noise_value, 0, 65535, 0, 255);
175 // Create a hue that changes with position and time
176 uint8_t sat = int32_t((x * 10 + y * 5 + now / 5)) % 256;
177 // Set the color
178 leds[i] = CHSV(170, sat, fl::clamp(255- sat, 64, 255));
179 }
180
181 FastLED.show();
182}
183
184void loop() {
185 uint32_t now = millis();
187
188 // for (int i = 0; i < NUM_LEDS; i++) {
189 // // Get the 3D position of this LED from the corkscrew map
190 // fl::vec3f pos = mapCorkScrew[i];
191
192 // // Create a wave pattern that moves up the corkscrew
193 // float wave = sin(pos.z * 0.2 - (now / 500.0));
194 // wave = (wave + 1.0) / 2.0; // Normalize to 0-1 range
195
196 // // Create a hue that changes with position and time
197 // uint8_t hue = int32_t((pos.x * 10 + pos.y * 5 + now / 20)) % 256;
198
199 // // Set brightness based on the wave pattern
200 // uint8_t val = 128 + 127 * wave;
201
202 // // Set the color
203 // leds[i] = CHSV(hue, 240, val);
204 // }
205
207 FastLED.show();
208}
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
uint8_t pos
Definition Blur.ino:11
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:58
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:123
central include file for FastLED, defines the CFastLED class/object
fl::vector< vec3f > makeCorkScrew(corkscrew_args args=corkscrew_args())
fl::ScreenMap screenMap
UITitle festivalStickTitle("Festival Stick")
void showGenerative()
#define NUM_LEDS
#define PIN_CLOCK
void setup()
#define PIN_DATA
UIDescription festivalStickDescription("Take a wooden walking stick, wrap dense LEDs around it like a corkscrew. Super simple but very awesome looking." "This assumes the dense 144 LEDs / meter.")
UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f)
corkscrew_args args
CLEDController * addController()
fl::vector< vec3f > mapCorkScrew
void loop()
uint32_t z[NUM_LAYERS]
Definition Fire2023.ino:84
ScreenMap makeScreenMap()
Definition Fire2023.ino:118
UISlider brightness("Brightness", 255, 0, 255, 1)
CLEDController * controller
Base definition for an LED controller.
void push_back(const T &value)
Definition vector.h:442
@ BGR
Blue, Green, Red (0210)
Definition eorder.h:20
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 PI
Definition math_macros.h:57
void clear(CRGB(&arr)[N])
Definition clear.h:8
FASTLED_FORCE_INLINE T clamp(T value, T min, T max)
Definition clamp.h:10
vec3< float > vec3f
Definition geometry.h:156
vec2< float > vec2f
Definition geometry.h:301
HeapVector< T > vector
Definition vector.h:1028
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Functions to generate and fill arrays with noise.
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