FastLED 3.10.10
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// Both strips use the board's default clocked-chipset pin pairs
41// (platforms/default_pins.h), because a literal is a guess about hardware
42// this sketch cannot see -- the Adafruit Feather nRF52840 boards exclude D1,
43// and Feather M4 has no pins 2 or 3.
44// A sketch or build flag defining these first still wins.
45#ifndef STRIP_0_DATA_PIN
46#define STRIP_0_DATA_PIN FL_PIN_SPI_DATA_1
47#endif
48#ifndef STRIP_0_CLOCK_PIN
49#define STRIP_0_CLOCK_PIN FL_PIN_SPI_CLOCK_1
50#endif
51#ifndef STRIP_1_DATA_PIN
52#define STRIP_1_DATA_PIN FL_PIN_SPI_DATA_2
53#endif
54#ifndef STRIP_1_CLOCK_PIN
55#define STRIP_1_CLOCK_PIN FL_PIN_SPI_CLOCK_2
56#endif
57
58
59CRGB leds_hd[NUM_LEDS] = {0}; // HD mode implies gamma.
60CRGB leds[NUM_LEDS] = {0}; // Software gamma mode.
61
62// This is the regular gamma correction function that we used to have
63// to do. It's used here to showcase the difference between APA102HD
64// mode which does the gamma correction for you.
66 CRGB out;
67 // dim8_raw are the old gamma correction functions.
68 out.r = dim8_raw(in.r);
69 out.g = dim8_raw(in.g);
70 out.b = dim8_raw(in.b);
71 return out;
72}
73
74void setup() {
75 delay(500); // power-up safety delay
76 // Two strips of LEDs, one in HD mode, one in software gamma mode.
79}
80
81uint8_t wrap_8bit(int i) {
82 // Module % operator here wraps a large "i" so that it is
83 // always in [0, 255] range when returned. For example, if
84 // "i" is 256, then this will return 0. If "i" is 257
85 // then this will return 1. No matter how big the "i" is, the
86 // output range will always be [0, 255]
87 return i % 256;
88}
89
90void loop() {
91 // Draw a a linear ramp of brightnesses to showcase the difference between
92 // the HD and non-HD mode.
93 for (int i = 0; i < NUM_LEDS; i++) {
94 uint8_t brightness = map(i, 0, NUM_LEDS - 1, 0, 255);
95 CRGB c(brightness, brightness, brightness); // Just make a shade of white.
96 leds_hd[i] = c; // The APA102HD leds do their own gamma correction.
97 CRGB c_gamma_corrected = software_gamma(c);
98 leds[i] = c_gamma_corrected; // Set the software gamma corrected
99 // values to the other strip.
100 }
101 FastLED.show(); // All leds are now written out.
102 delay(8); // Wait 8 milliseconds until the next frame.
103}
CRGB leds[1]
#define NUM_LEDS
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
#define STRIP_0_DATA_PIN
Definition Apa102HD.ino:46
CRGB software_gamma(const CRGB &in)
Definition Apa102HD.ino:65
#define STRIP_1_CLOCK_PIN
Definition Apa102HD.ino:55
void setup()
Definition Apa102HD.ino:74
#define STRIP_0_CLOCK_PIN
Definition Apa102HD.ino:49
#define STRIP_1_DATA_PIN
Definition Apa102HD.ino:52
CRGB leds_hd[NUM_LEDS]
Definition Apa102HD.ino:59
uint8_t wrap_8bit(int i)
Definition Apa102HD.ino:81
void loop()
Definition Apa102HD.ino:90
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:306
@ APA102
APA102 LED chipset.
Definition FastLED.h:301
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.