FastLED 3.9.15
Loading...
Searching...
No Matches
Corkscrew.h
Go to the documentation of this file.
1/*
2Basic cork screw test.
3
4This test is forward mapping, in which we test that
5the corkscrew is mapped to cylinder cartesian coordinates.
6
7Most of the time, you'll want the reverse mapping, that is
8drawing to a rectangular grid, and then mapping that to a corkscrew.
9
10However, to make sure the above mapping works correctly, we have
11to test that the forward mapping works correctly first.
12
13*/
14
15#include "fl/assert.h"
16#include "fl/corkscrew.h"
17#include "fl/grid.h"
18#include "fl/leds.h"
19#include "fl/screenmap.h"
20#include "fl/sstream.h"
21#include "fl/warn.h"
22#include "noise.h"
23#include <FastLED.h>
24// #include "vec3.h"
25
26using namespace fl;
27
28#define PIN_DATA 9
29
30#define NUM_LEDS 288
31#define CORKSCREW_TOTAL_LENGTH 100
32#define CORKSCREW_TOTAL_HEIGHT 23.25 // when height = 0, it's a circle.
33 // wrapped up over 19 turns
34#define CORKSCREW_TURNS 19 // Default to 19 turns
35
36// #define CM_BETWEEN_LEDS 1.0 // 1cm between LEDs
37// #define CM_LED_DIAMETER 0.5 // 0.5cm LED diameter
38
41 "Tests the ability to map a cork screw onto a 2D cylindrical surface");
42
43UISlider speed("Speed", 0.1f, 0.01f, 1.0f, 0.01f);
44
45UICheckbox allWhite("All White", false);
46UICheckbox splatRendering("Splat Rendering", true);
47
48// CRGB leds[NUM_LEDS];
49
50// Tested on a 288 led (2x 144 max density led strip) with 19 turns
51// with 23.25cm height, 19 turns, and ~15.5 LEDs per turn.
53 CORKSCREW_TURNS, // Default to 19 turns
54 NUM_LEDS, // Default to dense 144 leds.
55 0 // offset to account for gaps between segments
56);
57
58// Corkscrew::State corkscrewMap = fl::Corkscrew::generateMap(corkscrewInput);
60
61// Create a corkscrew with:
62// - 30cm total length (300mm)
63// - 5cm width (50mm)
64// - 2mm LED inner diameter
65// - 24 LEDs per turn
66// fl::ScreenMap screenMap = makeCorkScrew(NUM_LEDS,
67// 300.0f, 50.0f, 2.0f, 24.0f);
68
69// fl::vector<vec3f> mapCorkScrew = makeCorkScrew(args);
72
73void setup() {
74 int width = corkscrew.cylinder_width();
75 int height = corkscrew.cylinder_height();
76
77 frameBuffer.reset(width, height);
79
80 CRGB *leds = frameBuffer.data();
81 size_t num_leds = frameBuffer.size();
82
84 &FastLED.addLeds<WS2812, 3, BGR>(leds, num_leds);
85
86 fl::ScreenMap screenMap = xyMap.toScreenMap();
87 screenMap.setDiameter(.2f);
88
89 // Set the screen map for the controller
90 controller->setScreenMap(screenMap);
91}
92
93void loop() {
95 static float pos = 0;
96 pos += speed.value();
97 if (pos > corkscrew.size() - 1) {
98 pos = 0; // Reset to the beginning
99 }
100
101 if (allWhite) {
102 for (size_t i = 0; i < frameBuffer.size(); ++i) {
103 frameBuffer.data()[i] = CRGB(8, 8, 8);
104 }
105 }
106
107 if (splatRendering) {
108 Tile2x2_u8_wrap pos_tile = corkscrew.at_wrap(pos);
109 const CRGB color = CRGB::Blue;
110 // Draw each pixel in the 2x2 tile using the new wrapping API
111 for (int dx = 0; dx < 2; ++dx) {
112 for (int dy = 0; dy < 2; ++dy) {
113 auto data = pos_tile.at(dx, dy);
114 vec2i16 wrapped_pos = data.first; // Already wrapped position
115 uint8_t alpha = data.second; // Alpha value
116
117 if (alpha > 0) { // Only draw if there's some alpha
118 CRGB c = color;
119 c.nscale8(alpha); // Scale the color by the alpha value
120 frameBuffer.at(wrapped_pos.x, wrapped_pos.y) = c;
121 }
122 }
123 }
124 } else {
125 // None splat rendering, looks aweful.
126 vec2f pos_vec2f = corkscrew.at_exact(pos);
127 vec2i16 pos_i16 = vec2i16(round(pos_vec2f.x), round(pos_vec2f.y));
128 // Now map the cork screw position to the cylindrical buffer that we
129 // will draw.
130 frameBuffer.at(pos_i16.x, pos_i16.y) =
131 CRGB::Blue; // Draw a blue pixel at (w, h)
132 }
133 FastLED.show();
134}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
uint8_t pos
Definition Blur.ino:11
UICheckbox allWhite("All White", false)
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:62
central include file for FastLED, defines the CFastLED class/object
CLEDController * controller
Base definition for an LED controller.
WS2812 controller class.
Definition FastLED.h:210
static XYMap constructRectangularGrid(uint16_t width, uint16_t height, uint16_t offset=0)
Definition xymap.cpp:36
CorkscrewInput Input
Definition corkscrew.h:135
Definition grid.h:9
Data & at(uint16_t x, uint16_t y)
Definition tile2x2.cpp:57
@ BGR
Blue, Green, Red (0210)
Definition eorder.h:20
fl::ScreenMap screenMap
Definition Corkscrew.h:70
UITitle festivalStickTitle("Corkscrew")
Corkscrew corkscrew(corkscrewInput)
Corkscrew::Input corkscrewInput(CORKSCREW_TOTAL_LENGTH, CORKSCREW_TOTAL_HEIGHT, CORKSCREW_TURNS, NUM_LEDS, 0)
void setup()
Definition Corkscrew.h:73
UICheckbox splatRendering("Splat Rendering", true)
fl::Grid< CRGB > frameBuffer
Definition Corkscrew.h:71
#define CORKSCREW_TURNS
Definition Corkscrew.h:34
#define CORKSCREW_TOTAL_LENGTH
Definition Corkscrew.h:31
UIDescription festivalStickDescription("Tests the ability to map a cork screw onto a 2D cylindrical surface")
#define CORKSCREW_TOTAL_HEIGHT
Definition Corkscrew.h:32
void loop()
Definition Corkscrew.h:93
uint16_t speed
Definition funky.cpp:82
XYMap xyMap
Definition gfx.cpp:8
void clear(CRGB(&arr)[N])
Definition clear.h:13
vec2< float > vec2f
Definition geometry.h:318
vec2< int16_t > vec2i16
Definition geometry.h:320
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Functions to generate and fill arrays with noise.
Corkscrew projection utilities.
CRGB & nscale8(uint8_t scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition crgb.cpp:88
@ 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 round(x)
Definition util.h:10