FastLED 3.9.15
Loading...
Searching...
No Matches
old.h
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/stl/assert.h"
14#include "fl/math/screenmap.h"
15#include "fl/log/log.h"
16#include "noise.h"
17#include <FastLED.h>
18// #include "fl::vec3.h"
19
20
21// Power management settings
22#define VOLTS 5
23#define MAX_AMPS 1
24
25
26#define PIN_DATA 9
27#define PIN_CLOCK 7
28
29// Pin could have been tied to ground, instead it's tied to another pin.
30#define PIN_BUTTON 1
31#define PIN_GRND 2
32
33#define NUM_LEDS 288
34// #define CM_BETWEEN_LEDS 1.0 // 1cm between LEDs
35// #define CM_LED_DIAMETER 0.5 // 0.5cm LED diameter
36
37fl::UITitle festivalStickTitle("Festival Stick - Classic Version");
39 "Take a wooden walking stick, wrap dense LEDs around it like a corkscrew. Super simple but very awesome looking. "
40 "This classic version uses 3D Perlin noise to create organic, flowing patterns around the cylindrical surface. "
41 "Assumes dense 144 LEDs/meter (288 total LEDs).");
42
43// UIHelp festivalStickHelp("Festival Stick - Classic Guide");
44
45// UIHelp technicalHelp("Technical Details - Classic Festival Stick");
46// UIHelp usageHelp("Usage Guide - Classic Festival Stick");
47// UIHelp physicalBuildHelp("Building Your Festival Stick");
48
49
50fl::UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f);
52
53// Adding a brightness slider
54fl::UISlider brightness("Brightness", 16, 0, 255, 1); // Brightness from 0 to 255
55
57
58
59// fl::vector<vec3f>
62 float leds_per_turn = 15.5;
63 float width_cm = 1.0;
64};
65
67 // int num_leds, float leds_per_turn, float width_cm
68 int num_leds = args.num_leds;
69 float leds_per_turn = args.leds_per_turn;
70 float width_cm = args.width_cm;
71
72 const float circumference = leds_per_turn;
73 const float radius = circumference / (2.0 * FL_PI); // radius in mm
74 const float angle_per_led = 2.0 * FL_PI / leds_per_turn; // degrees per LED
75 const float total_angle_radians = angle_per_led * num_leds;
76 const float total_turns = total_angle_radians / (2.0 * FL_PI); // total turns
77 const float height_per_turn_cm = width_cm; // 10cm height per turn
78 const float height_per_led =
79 height_per_turn_cm /
80 leds_per_turn; // this is the changing height per led.
81 const float total_height =
82 height_per_turn_cm * total_turns; // total height of the corkscrew
84 for (int i = 0; i < num_leds; i++) {
85 float angle = i * angle_per_led; // angle in radians
86 float height = (i / leds_per_turn) * height_per_turn_cm; // height in cm
87
88 // Calculate the x, y, z coordinates for the corkscrew
89 float x = radius * fl::cos(angle); // x coordinate
90 float z = radius * fl::sin(angle); // y coordinate
91 float y = height; // z coordinate
92
93 // Store the 3D coordinates in the fl::vector
94 vec3f led_position(x, y, z);
95 // screenMap.set(i, led_position);
96 out.push_back(led_position);
97 }
98 return out;
99}
100
101
103 // Create a fl::ScreenMap for the corkscrew
104 fl::vector<vec2f> points(args.num_leds);
105
106 int num_leds = args.num_leds;
107 float leds_per_turn = args.leds_per_turn;
108 float width_cm = args.width_cm;
109
110
111 const float circumference = leds_per_turn;
112 const float radius = circumference / (2.0 * FL_PI); // radius in mm
113 const float angle_per_led = 2.0 * FL_PI / leds_per_turn; // degrees per LED
114 const float height_per_turn_cm = width_cm; // 10cm height per turn
115 const float height_per_led =
116 height_per_turn_cm /
117 leds_per_turn * 1.3; // this is the changing height per led.
118
119
120
121 for (int i = 0; i < num_leds; i++) {
122 float angle = i * angle_per_led; // angle in radians
123 float r = radius + 10 + i * height_per_led; // height in cm
124
125 // Calculate the x, y coordinates for the corkscrew
126 float x = r * fl::cos(angle); // x coordinate
127 float y = r * fl::sin(angle); // y coordinate
128
129 // Store the 2D coordinates in the fl::vector
130 points[i] = vec2f(x, y);
131 }
132
133 FL_WARN("Creating fl::ScreenMap with:\n" << points);
134
135 // Create a fl::ScreenMap from the points
136 fl::ScreenMap screenMap(points.data(), num_leds, .5);
137 return screenMap;
138}
139
140
141// Create a corkscrew with:
142// - 30cm total length (300mm)
143// - 5cm width (50mm)
144// - 2mm LED inner diameter
145// - 24 LEDs per turn
146// fl::ScreenMap screenMap = makeCorkScrew(NUM_LEDS,
147// 300.0f, 50.0f, 2.0f, 24.0f);
148
152
153
158
159void setup() {
160 pinMode(PIN_GRND, OUTPUT);
161 digitalWrite(PIN_GRND, LOW); // Set ground pin to low
162 button.addRealButton(Button(PIN_BUTTON));
164 //screenMap = fl::ScreenMap::Circle(NUM_LEDS, 1.5f, 0.5f, 1.0f);
165 auto controller = addController();
166 // Set the screen map for the controller
167 controller->setScreenMap(screenMap);
168
169 // Set power management. This allows this festival stick to conformatable
170 // run on any USB battery that can output at least 1A at 5V.
171 // Keep in mind that this sketch is designed to use APA102HD mode, which will
172 // result in even lowwer run power consumption, since the power mode does not take
173 // into account the APA102HD gamma correction. However it is still a correct upper bound
174 // that will match the ledset exactly when the display tries to go full white.
175 FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS * 1000);
176 // set brightness 8
177 FastLED.setBrightness(brightness.as_int());
178 button.onChanged([](fl::UIButton& but) {
179 // This function is called when the button is pressed
180 // If the button is pressed, show the generative pattern
181 if (but.isPressed()) {
182 FL_WARN("Button pressed");
183 } else {
184 FL_WARN("NOT Button pressed");
185 }
186 });
187
188}
189
190
191void showGenerative(uint32_t now) {
192 // This function is called to show the generative pattern
193 for (int i = 0; i < NUM_LEDS; i++) {
194 // Get the 2D position of this LED from the screen map
196 float x = pos.x;
197 float y = pos.y;
198 float z = pos.z;
199
200 x*= 20.0f * ledsScale.value();
201 y*= 20.0f * ledsScale.value();
202 z*= 20.0f * ledsScale.value();
203
204 uint16_t noise_value = inoise16(x,y,z, now / 100);
205 // Normalize the noise value to 0-255
206 uint8_t brightness = map(noise_value, 0, 65535, 0, 255);
207 // Create a hue that changes with position and time
208 uint8_t sat = int32_t((x * 10 + y * 5 + now / 5)) % 256;
209 // Set the color
210 leds[i] = fl::CHSV(170, sat, fl::clamp(255- sat, 64, 255));
211 }
212}
213
214void loop() {
215 uint32_t now = millis();
217 showGenerative(now);
218 FastLED.show();
219}
#define NUM_LEDS
#define PIN_DATA
fl::CRGB leds[NUM_LEDS]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
int y
Definition simple.h:93
int x
Definition simple.h:92
uint8_t pos
Definition Blur.ino:11
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:267
uint32_t z[NUM_LAYERS]
Definition Fire2023.h:93
fl::ScreenMap makeScreenMap()
Definition Fire2023.h:127
CLEDController * controller
bool isPressed() const FL_NOEXCEPT
Definition button.h:45
T * data() FL_NOEXCEPT
Definition vector.h:619
void push_back(const T &value) FL_NOEXCEPT
Definition vector.h:624
fl::CLEDController CLEDController
#define PIN_CLOCK
Definition curr.h:51
constexpr EOrder BGR
Definition eorder.h:22
fl::ScreenMap screenMap
Definition Corkscrew.h:101
fl::u16 inoise16(fl::u32 x, fl::u32 y, fl::u32 z, fl::u32 t)
#define FL_WARN(X)
Definition log.h:276
Centralized logging categories for FastLED hardware interfaces and subsystems.
#define FL_PI
Definition math.h:26
void clear(CRGB(&arr)[N])
Definition clear.h:12
vec3< float > vec3f
Definition geometry.h:185
enable_if< is_fixed_point< T >::value, T >::type cos(T angle) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type sin(T angle) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NOEXCEPT
fl::vector< vec3f > makeCorkScrew(corkscrew_args args=corkscrew_args())
Definition old.h:66
fl::ScreenMap screenMap
Definition old.h:151
fl::UIDescription festivalStickDescription("Take a wooden walking stick, wrap dense LEDs around it like a corkscrew. Super simple but very awesome looking. " "This classic version uses 3D Perlin noise to create organic, flowing patterns around the cylindrical surface. " "Assumes dense 144 LEDs/meter (288 total LEDs).")
#define VOLTS
Definition old.h:22
fl::UIButton button("Button")
#define PIN_BUTTON
Definition old.h:30
#define NUM_LEDS
Definition old.h:33
void setup()
Definition old.h:159
void showGenerative(uint32_t now)
Definition old.h:191
corkscrew_args args
Definition old.h:149
CLEDController * addController()
Definition old.h:154
#define PIN_GRND
Definition old.h:31
fl::vector< vec3f > mapCorkScrew
Definition old.h:150
fl::UITitle festivalStickTitle("Festival Stick - Classic Version")
#define MAX_AMPS
Definition old.h:23
fl::UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f)
void loop()
Definition old.h:214
int num_leds
Definition old.h:61
float leds_per_turn
Definition old.h:62
float width_cm
Definition old.h:63
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38