FastLED 3.9.15
Loading...
Searching...
No Matches
curr.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
29#define PIN_DATA 3
30#define PIN_CLOCK 4
31
32
33#define NUM_LEDS 288
34#define CORKSCREW_TOTAL_LENGTH 100 // 100 cm
35#define CORKSCREW_TOTAL_HEIGHT \
36 23.25 // when height = 0, it's a circle.
37 // wrapped up over 19 turns
38#define CORKSCREW_TURNS 20.5 // Default to 19 turns
39
40// #define CM_BETWEEN_LEDS 1.0 // 1cm between LEDs
41// #define CM_LED_DIAMETER 0.5 // 0.5cm LED diameter
42
45 "Tests the ability to map a cork screw onto a 2D cylindrical surface");
46
47UISlider speed("Speed", 0.1f, 0.01f, 1.0f, 0.01f);
48
49UICheckbox allWhite("All White", false);
50UICheckbox splatRendering("Splat Rendering", true);
51
52// CRGB leds[NUM_LEDS];
53
54// Tested on a 288 led (2x 144 max density led strip) with 19 turns
55// with 23.25cm height, 19 turns, and ~15.5 LEDs per turn.
58
59// Corkscrew::State corkscrewMap = fl::Corkscrew::generateMap(corkscrewInput);
61
62// Create a corkscrew with:
63// - 30cm total length (300mm)
64// - 5cm width (50mm)
65// - 2mm LED inner diameter
66// - 24 LEDs per turn
67// fl::ScreenMap screenMap = makeCorkScrew(NUM_LEDS,
68// 300.0f, 50.0f, 2.0f, 24.0f);
69
70// fl::vector<vec3f> mapCorkScrew = makeCorkScrew(args);
73
74
75
76void setup() {
77 int width = corkscrew.cylinder_width();
78 int height = corkscrew.cylinder_height();
79
80 frameBuffer.reset(width, height);
82
83 CRGB *leds = frameBuffer.data();
84 size_t num_leds = frameBuffer.size();
85
87
88 // CLEDController *controller =
89 // &FastLED.addLeds<WS2812, 3, BGR>(leds, num_leds);
90
91 fl::ScreenMap screenMap = xyMap.toScreenMap();
92 screenMap.setDiameter(.2f);
93
94 // Set the screen map for the controller
95 controller->setScreenMap(screenMap);
96}
97
98void loop() {
99 uint32_t now = millis();
100 // fl::clear(lesdds);
102
103 static float pos = 0;
104
105 // Update the corkscrew mapping every second
106 // w = (w + 1) % CORKSCREW_WIDTH;
107 // frameBuffer.
108 pos += speed.value();
109 if (pos > corkscrew.size() - 1) {
110 pos = 0; // Reset to the beginning
111 }
112 if (allWhite) {
113 for (size_t i = 0; i < frameBuffer.size(); ++i) {
114 frameBuffer.data()[i] = CRGB(8, 8, 8);
115 }
116 }
117
118 if (splatRendering) {
119 Tile2x2_u8_wrap pos_tile = corkscrew.at_wrap(pos);
120 const CRGB color = CRGB::Blue;
121 // Draw each pixel in the 2x2 tile using the new wrapping API
122 for (int dx = 0; dx < 2; ++dx) {
123 for (int dy = 0; dy < 2; ++dy) {
124 auto data = pos_tile.at(dx, dy);
125 vec2i16 wrapped_pos = data.first; // Already wrapped position
126 uint8_t alpha = data.second; // Alpha value
127
128 if (alpha > 0) { // Only draw if there's some alpha
129 CRGB c = color;
130 c.nscale8(alpha); // Scale the color by the alpha value
131 frameBuffer.at(wrapped_pos.x, wrapped_pos.y) = c;
132 }
133 }
134 }
135 } else {
136 // None splat rendering, looks aweful.
137 vec2f pos_vec2f = corkscrew.at_exact(pos);
138 vec2i16 pos_i16 = vec2i16(round(pos_vec2f.x), round(pos_vec2f.y));
139 // Now map the cork screw position to the cylindrical buffer that we
140 // will draw.
141 frameBuffer.at(pos_i16.x, pos_i16.y) =
142 CRGB::Blue; // Draw a blue pixel at (w, h)
143 }
144 FastLED.show();
145}
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
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:123
central include file for FastLED, defines the CFastLED class/object
CLEDController * controller
Base definition for an LED controller.
CorkscrewInput Input
Definition corkscrew.h:135
Definition grid.h:9
Data & at(uint16_t x, uint16_t y)
Definition tile2x2.cpp:57
static XYMap constructRectangularGrid(uint16_t width, uint16_t height, uint16_t offset=0)
Definition xymap.cpp:36
UITitle festivalStickTitle("Corkscrew")
Corkscrew corkscrew(corkscrewInput)
Corkscrew::Input corkscrewInput(CORKSCREW_TOTAL_LENGTH, CORKSCREW_TOTAL_HEIGHT, CORKSCREW_TURNS, NUM_LEDS, 0)
#define PIN_CLOCK
Definition curr.h:30
void setup()
Definition curr.h:76
UICheckbox splatRendering("Splat Rendering", true)
UIDescription festivalStickDescription("Tests the ability to map a cork screw onto a 2D cylindrical surface")
void loop()
Definition curr.h:98
@ BGR
Blue, Green, Red (0210)
Definition eorder.h:20
fl::ScreenMap screenMap
Definition Corkscrew.h:70
Corkscrew corkscrew(corkscrewInput)
Corkscrew::Input corkscrewInput(CORKSCREW_TOTAL_LENGTH, CORKSCREW_TOTAL_HEIGHT, CORKSCREW_TURNS, NUM_LEDS, 0)
#define PIN_DATA
Definition Corkscrew.h:28
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
#define CORKSCREW_TOTAL_HEIGHT
Definition Corkscrew.h:32
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