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");
40 "Take a wooden walking stick, wrap dense LEDs around it like a corkscrew. Super simple but very awesome looking."
41 "This assumes the dense 144 LEDs / meter.");
42
43
44
45UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f);
46UIButton button("Button");
47
48
50
51
52// fl::vector<vec3f>
53struct corkscrew_args {
54 int num_leds = NUM_LEDS;
55 float leds_per_turn = 15.5;
56 float width_cm = 1.0;
57};
58
60 // int num_leds, float leds_per_turn, float width_cm
61 int num_leds = args.num_leds;
62 float leds_per_turn = args.leds_per_turn;
63 float width_cm = args.width_cm;
64
65 const float circumference = leds_per_turn;
66 const float radius = circumference / (2.0 * PI); // radius in mm
67 const float angle_per_led = 2.0 * PI / leds_per_turn; // degrees per LED
68 const float total_angle_radians = angle_per_led * num_leds;
69 const float total_turns = total_angle_radians / (2.0 * PI); // total turns
70 const float height_per_turn_cm = width_cm; // 10cm height per turn
71 const float height_per_led =
72 height_per_turn_cm /
73 leds_per_turn; // this is the changing height per led.
74 const float total_height =
75 height_per_turn_cm * total_turns; // total height of the corkscrew
77 for (int i = 0; i < num_leds; i++) {
78 float angle = i * angle_per_led; // angle in radians
79 float height = (i / leds_per_turn) * height_per_turn_cm; // height in cm
80
81 // Calculate the x, y, z coordinates for the corkscrew
82 float x = radius * cos(angle); // x coordinate
83 float z = radius * sin(angle); // y coordinate
84 float y = height; // z coordinate
85
86 // Store the 3D coordinates in the vector
87 vec3f led_position(x, y, z);
88 // screenMap.set(i, led_position);
89 out.push_back(led_position);
90 }
91 return out;
92}
93
94
96 // Create a ScreenMap for the corkscrew
97 fl::vector<vec2f> points(args.num_leds);
98
99 int num_leds = args.num_leds;
100 float leds_per_turn = args.leds_per_turn;
101 float width_cm = args.width_cm;
102
103
104 const float circumference = leds_per_turn;
105 const float radius = circumference / (2.0 * PI); // radius in mm
106 const float angle_per_led = 2.0 * PI / leds_per_turn; // degrees per LED
107 const float height_per_turn_cm = width_cm; // 10cm height per turn
108 const float height_per_led =
109 height_per_turn_cm /
110 leds_per_turn * 1.3; // this is the changing height per led.
111
112
113
114 for (int i = 0; i < num_leds; i++) {
115 float angle = i * angle_per_led; // angle in radians
116 float r = radius + 10 + i * height_per_led; // height in cm
117
118 // Calculate the x, y coordinates for the corkscrew
119 float x = r * cos(angle); // x coordinate
120 float y = r * sin(angle); // y coordinate
121
122 // Store the 2D coordinates in the vector
123 points[i] = vec2f(x, y);
124 }
125
126 FASTLED_WARN("Creating ScreenMap with:\n" << points);
127
128 // Create a ScreenMap from the points
129 fl::ScreenMap screenMap(points.data(), num_leds, .5);
130 return screenMap;
131}
132
133
134// Create a corkscrew with:
135// - 30cm total length (300mm)
136// - 5cm width (50mm)
137// - 2mm LED inner diameter
138// - 24 LEDs per turn
139// fl::ScreenMap screenMap = makeCorkScrew(NUM_LEDS,
140// 300.0f, 50.0f, 2.0f, 24.0f);
141
145
146
151
152void setup() {
153 pinMode(PIN_GRND, OUTPUT);
154 digitalWrite(PIN_GRND, LOW); // Set ground pin to low
155 button.addRealButton(Button(PIN_BUTTON));
157 //screenMap = ScreenMap::Circle(NUM_LEDS, 1.5f, 0.5f, 1.0f);
158 auto controller = addController();
159 // Set the screen map for the controller
160 controller->setScreenMap(screenMap);
161
162 // Set power management. This allows this festival stick to conformatable
163 // run on any USB battery that can output at least 1A at 5V.
164 // Keep in mind that this sketch is designed to use APA102HD mode, which will
165 // result in even lowwer run power consumption, since the power mode does not take
166 // into account the APA102HD gamma correction. However it is still a correct upper bound
167 // that will match the ledset exactly when the display tries to go full white.
168 FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS * 1000);
169 button.onChanged([](UIButton& but) {
170 // This function is called when the button is pressed
171 // If the button is pressed, show the generative pattern
172 if (but.isPressed()) {
173 FASTLED_WARN("Button pressed");
174 } else {
175 FASTLED_WARN("NOT Button pressed");
176 }
177 });
178
179}
180
181
182void showGenerative(uint32_t now) {
183 // This function is called to show the generative pattern
184 for (int i = 0; i < NUM_LEDS; i++) {
185 // Get the 2D position of this LED from the screen map
187 float x = pos.x;
188 float y = pos.y;
189 float z = pos.z;
190
191 x*= 20.0f * ledsScale.value();
192 y*= 20.0f * ledsScale.value();
193 z*= 20.0f * ledsScale.value();
194
195 uint16_t noise_value = inoise16(x,y,z, now / 100);
196 // Normalize the noise value to 0-255
197 uint8_t brightness = map(noise_value, 0, 65535, 0, 255);
198 // Create a hue that changes with position and time
199 uint8_t sat = int32_t((x * 10 + y * 5 + now / 5)) % 256;
200 // Set the color
201 leds[i] = CHSV(170, sat, fl::clamp(255- sat, 64, 255));
202 }
203}
204
205void loop() {
206 uint32_t now = millis();
208 showGenerative(now);
209 FastLED.show();
210}
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.
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:123
central include file for FastLED, defines the CFastLED class/object
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:493
bool isPressed() const
Definition ui.h:111
fl::ScreenMap screenMap
Definition curr.h:119
#define VOLTS
Definition curr.h:24
#define PIN_BUTTON
Definition curr.h:31
UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f)
#define PIN_CLOCK
Definition curr.h:28
#define PIN_DATA
Definition curr.h:27
#define PIN_GRND
Definition curr.h:32
#define MAX_AMPS
Definition curr.h:25
@ 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:63
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:173
vec2< float > vec2f
Definition geometry.h:318
HeapVector< T, Allocator > vector
Definition vector.h:1074
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Functions to generate and fill arrays with noise.
fl::vector< vec3f > makeCorkScrew(corkscrew_args args=corkscrew_args())
Definition old.h:59
fl::ScreenMap screenMap
Definition old.h:144
UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f)
void setup()
Definition old.h:152
void showGenerative(uint32_t now)
Definition old.h:182
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.")
corkscrew_args args
Definition old.h:142
CLEDController * addController()
Definition old.h:147
fl::vector< vec3f > mapCorkScrew
Definition old.h:143
UITitle festivalStickTitle("Festival Stick")
void loop()
Definition old.h:205
int num_leds
Definition curr.h:71
float leds_per_turn
Definition curr.h:72
float width_cm
Definition curr.h:73
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
UIButton button("Trigger")