FastLED 3.9.15
Loading...
Searching...
No Matches
Apa102HD.ino
Go to the documentation of this file.
1// @filter: (board is not stm32f103cb)
2
31
32
33#include <Arduino.h>
34#include <FastLED.h>
35#include <lib8tion.h>
36
37#define NUM_LEDS 20
38// uint8_t DATA_PIN, uint8_t CLOCK_PIN,
39
40#define STRIP_0_DATA_PIN 1
41#define STRIP_0_CLOCK_PIN 2
42#define STRIP_1_DATA_PIN 3
43#define STRIP_1_CLOCK_PIN 4
44
45
46CRGB leds_hd[NUM_LEDS] = {0}; // HD mode implies gamma.
47CRGB leds[NUM_LEDS] = {0}; // Software gamma mode.
48
49// This is the regular gamma correction function that we used to have
50// to do. It's used here to showcase the difference between APA102HD
51// mode which does the gamma correction for you.
53 CRGB out;
54 // dim8_raw are the old gamma correction functions.
55 out.r = dim8_raw(in.r);
56 out.g = dim8_raw(in.g);
57 out.b = dim8_raw(in.b);
58 return out;
59}
60
61void setup() {
62 delay(500); // power-up safety delay
63 // Two strips of LEDs, one in HD mode, one in software gamma mode.
66}
67
68uint8_t wrap_8bit(int i) {
69 // Module % operator here wraps a large "i" so that it is
70 // always in [0, 255] range when returned. For example, if
71 // "i" is 256, then this will return 0. If "i" is 257
72 // then this will return 1. No matter how big the "i" is, the
73 // output range will always be [0, 255]
74 return i % 256;
75}
76
77void loop() {
78 // Draw a a linear ramp of brightnesses to showcase the difference between
79 // the HD and non-HD mode.
80 for (int i = 0; i < NUM_LEDS; i++) {
81 uint8_t brightness = map(i, 0, NUM_LEDS - 1, 0, 255);
82 CRGB c(brightness, brightness, brightness); // Just make a shade of white.
83 leds_hd[i] = c; // The APA102HD leds do their own gamma correction.
84 CRGB c_gamma_corrected = software_gamma(c);
85 leds[i] = c_gamma_corrected; // Set the software gamma corrected
86 // values to the other strip.
87 }
88 FastLED.show(); // All leds are now written out.
89 delay(8); // Wait 8 milliseconds until the next frame.
90}
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
#define STRIP_0_DATA_PIN
Definition Apa102HD.ino:40
CRGB software_gamma(const CRGB &in)
Definition Apa102HD.ino:52
#define STRIP_1_CLOCK_PIN
Definition Apa102HD.ino:43
void setup()
Definition Apa102HD.ino:61
#define STRIP_0_CLOCK_PIN
Definition Apa102HD.ino:41
#define STRIP_1_DATA_PIN
Definition Apa102HD.ino:42
CRGB leds_hd[NUM_LEDS]
Definition Apa102HD.ino:46
uint8_t wrap_8bit(int i)
Definition Apa102HD.ino:68
void loop()
Definition Apa102HD.ino:77
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:267
@ APA102
APA102 LED chipset.
Definition FastLED.h:262
constexpr EOrder RGB
Definition eorder.h:17
fl::CRGB CRGB
Definition crgb.h:25
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.