FastLED 3.9.15
Loading...
Searching...
No Matches
curr.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
6LEDs are mapped to a sprial, with the inner portion of the spiral being the top,
7the outer most portion being the bottom.
8
9*/
10
11#include "fl/assert.h"
12#include "fl/corkscrew.h"
13#include "fl/screenmap.h"
14#include "fl/warn.h"
15#include "fl/sstream.h"
16#include "fl/leds.h"
17#include "noise.h"
18#include <FastLED.h>
19// #include "vec3.h"
20
21using namespace fl;
22
23// Power management settings
24#define VOLTS 5
25#define MAX_AMPS 1
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 CORKSCREW_TOTAL_HEIGHT \
36 23.25f // Total height of the corkscrew in centimeters for 144 densly
37 // wrapped up over 19 turns
38#define CORKSCREW_TURNS 19 // Default to 19 turns
39// #define CM_BETWEEN_LEDS 1.0 // 1cm between LEDs
40// #define CM_LED_DIAMETER 0.5 // 0.5cm LED diameter
41
42#define CORKSCREW_WIDTH 16
43#define CORKSCREW_HEIGHT 19
44
45
46UITitle festivalStickTitle("Festival Stick");
48 "Take a wooden walking stick, wrap dense LEDs around it like a corkscrew. "
49 "Super simple but very awesome looking."
50 "This assumes the dense 144 LEDs / meter.");
51
52UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f);
53UIButton button("Button");
54
56
57// Tested on a 288 led (2x 144 max density led strip) with 19 turns
58// with 23.25cm height, 19 turns, and ~15.5 LEDs per turn.
61 CORKSCREW_TURNS * 2.0f * PI, // Default to 19 turns
62 0, // offset to account for gaps between segments
63 NUM_LEDS, // Default to dense 144 leds.
64 );
65
66// Corkscrew::Output corkscrewMap = fl::Corkscrew::generateMap(corkscrewInput);
68
69// Used only for the fl::ScreenMap generation.
72 float leds_per_turn = 15.5;
73 float width_cm = 1.0;
74};
75
77 // Create a ScreenMap for the corkscrew
78 fl::vector<vec2f> points(args.num_leds);
79
80 int num_leds = args.num_leds;
81 float leds_per_turn = args.leds_per_turn;
82 float width_cm = args.width_cm;
83
84 const float circumference = leds_per_turn;
85 const float radius = circumference / (2.0 * PI); // radius in mm
86 const float angle_per_led = 2.0 * PI / leds_per_turn; // degrees per LED
87 const float height_per_turn_cm = width_cm; // 10cm height per turn
88 const float height_per_led = height_per_turn_cm / leds_per_turn *
89 1.3; // this is the changing height per led.
90
91 for (int i = 0; i < num_leds; i++) {
92 float angle = i * angle_per_led; // angle in radians
93 float r = radius + 10 + i * height_per_led; // height in cm
94
95 // Calculate the x, y coordinates for the corkscrew
96 float x = r * cos(angle); // x coordinate
97 float y = r * sin(angle); // y coordinate
98
99 // Store the 2D coordinates in the vector
100 points[i] = vec2f(x, y);
101 }
102
103 FASTLED_WARN("Creating ScreenMap with:\n" << points);
104
105 // Create a ScreenMap from the points
106 fl::ScreenMap screenMap(points.data(), num_leds, .5);
107 return screenMap;
108}
109
110// Create a corkscrew with:
111// - 30cm total length (300mm)
112// - 5cm width (50mm)
113// - 2mm LED inner diameter
114// - 24 LEDs per turn
115// fl::ScreenMap screenMap = makeCorkScrew(NUM_LEDS,
116// 300.0f, 50.0f, 2.0f, 24.0f);
117
118// fl::vector<vec3f> mapCorkScrew = makeCorkScrew(args);
120
126
127void setup() {
128 pinMode(PIN_GRND, OUTPUT);
129 digitalWrite(PIN_GRND, LOW); // Set ground pin to low
130 button.addRealButton(Button(PIN_BUTTON));
133 // screenMap = ScreenMap::Circle(NUM_LEDS, 1.5f, 0.5f, 1.0f);
134 auto controller = addController();
135 // Set the screen map for the controller
136 controller->setScreenMap(screenMap);
137
138 // Set power management. This allows this festival stick to conformatable
139 // run on any USB battery that can output at least 1A at 5V.
140 // Keep in mind that this sketch is designed to use APA102HD mode, which
141 // will result in even lowwer run power consumption, since the power mode
142 // does not take into account the APA102HD gamma correction. However it is
143 // still a correct upper bound that will match the ledset exactly when the
144 // display tries to go full white.
145 FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS * 1000);
146 button.onChanged([](UIButton &but) {
147 // This function is called when the button is pressed
148 // If the button is pressed, show the generative pattern
149 if (but.isPressed()) {
150 FASTLED_WARN("Button pressed");
151 } else {
152 FASTLED_WARN("NOT Button pressed");
153 }
154 });
155}
156
157void printOutput(const Corkscrew::Output& output) {
158 fl::sstream stream;
159 stream << "Corkscrew Output:\n";
160 stream << "Width: " << output.width << "\n";
161 stream << "Height: " << output.height << "\n";
162 // stream << "Mapping: \n";
163 // for (const auto &point : output.mapping) {
164 // stream << point << "\n";
165 // }
166 FASTLED_WARN(stream.str());
167}
168
169
170
172
173void loop() {
174 uint32_t now = millis();
177
178 static int w = 0;
179
180 EVERY_N_MILLIS(300) {
181 // Update the corkscrew mapping every second
182 w = (w + 1) % CORKSCREW_WIDTH;
183 }
184
185
186 // draw a blue line down the middle
187 for (int i = 0; i < CORKSCREW_HEIGHT; ++i) {
189 frameBuffer.at((w + 1) % CORKSCREW_WIDTH, i) = CRGB::Blue;
191 frameBuffer.at((w + 2) % CORKSCREW_WIDTH, i) = CRGB::Blue;
193 }
194
195
196 // printOutput(corkscrewMap);
197
198 for (int i = 0; i < NUM_LEDS; ++i) {
199 // Get the position in the frame buffer
201 // Draw the tile to the frame buffer
202 CRGB c = frameBuffer.at(pos.x, pos.y);
203 leds[i] = c;
204
205 FASTLED_WARN_IF(i < 16, "LED " << i << " at position: "
206 << pos.x << ", " << pos.y
207 << " with color: " << c);
208
209 }
210
211 FastLED.show();
212}
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
ScreenMap makeScreenMap()
Definition Fire2023.ino:118
CLEDController * controller
Base definition for an LED controller.
CorkscrewOutput Output
Definition corkscrew.h:120
CorkscrewInput Input
Definition corkscrew.h:119
const Str & str() const
Definition strstream.h:49
bool isPressed() const
Definition ui.h:111
Corkscrew projection utilities.
void printOutput(const Corkscrew::Output &output)
Definition curr.h:157
fl::ScreenMap screenMap
Definition curr.h:119
#define VOLTS
Definition curr.h:24
#define PIN_BUTTON
Definition curr.h:31
#define CORKSCREW_HEIGHT
Definition curr.h:43
UISlider ledsScale("Leds scale", 0.1f, 0.1f, 1.0f, 0.01f)
Corkscrew corkscrew(corkscrewInput)
#define PIN_CLOCK
Definition curr.h:28
void setup()
Definition curr.h:127
#define PIN_DATA
Definition curr.h:27
Corkscrew::Input corkscrewInput(CORKSCREW_TOTAL_HEIGHT, CORKSCREW_TURNS *2.0f *PI, 0, NUM_LEDS,)
#define CORKSCREW_WIDTH
Definition curr.h:42
#define CORKSCREW_TURNS
Definition curr.h:38
CLEDController * addController()
Definition curr.h:121
#define PIN_GRND
Definition curr.h:32
LedsXY< CORKSCREW_WIDTH, CORKSCREW_HEIGHT > frameBuffer
Definition curr.h:171
#define MAX_AMPS
Definition curr.h:25
UITitle festivalStickTitle("Festival Stick")
#define CORKSCREW_TOTAL_HEIGHT
Definition curr.h:35
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.")
void loop()
Definition curr.h:173
@ BGR
Blue, Green, Red (0210)
Definition eorder.h:20
#define EVERY_N_MILLIS(N)
Checks whether to execute a block of code every N milliseconds.
Definition lib8tion.h:1297
#define PI
Definition math_macros.h:63
void clear(CRGB(&arr)[N])
Definition clear.h:8
vec2< float > vec2f
Definition geometry.h:318
StrStream sstream
Definition sstream.h:6
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.
#define NUM_LEDS
Definition old.h:34
corkscrew_args args
Definition old.h:142
int num_leds
Definition curr.h:71
float leds_per_turn
Definition curr.h:72
float width_cm
Definition curr.h:73
@ Blue
<div style='background:#0000FF;width:4em;height:4em;'></div>
Definition crgb.h:506
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55
#define FASTLED_WARN
Definition warn.h:7
#define FASTLED_WARN_IF
Definition warn.h:8
UIButton button("Trigger")