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