FastLED 3.9.7
Loading...
Searching...
No Matches
Apa102HD.ino
Go to the documentation of this file.
1
29
30
31#include <Arduino.h>
32#include <FastLED.h>
33#include <lib8tion.h>
34
35#define NUM_LEDS 20
36// uint8_t DATA_PIN, uint8_t CLOCK_PIN,
37
38#define STRIP_0_DATA_PIN 1
39#define STRIP_0_CLOCK_PIN 2
40#define STRIP_1_DATA_PIN 3
41#define STRIP_1_CLOCK_PIN 4
42
43
44CRGB leds_hd[NUM_LEDS] = {0}; // HD mode implies gamma.
45CRGB leds[NUM_LEDS] = {0}; // Software gamma mode.
46
47// This is the regular gamma correction function that we used to have
48// to do. It's used here to showcase the difference between APA102HD
49// mode which does the gamma correction for you.
50CRGB software_gamma(const CRGB& in) {
51 CRGB out;
52 // dim8_raw are the old gamma correction functions.
53 out.r = dim8_raw(in.r);
54 out.g = dim8_raw(in.g);
55 out.b = dim8_raw(in.b);
56 return out;
57}
58
59void setup() {
60 delay(500); // power-up safety delay
61 // Two strips of LEDs, one in HD mode, one in software gamma mode.
62 FastLED.addLeds<APA102HD, STRIP_0_DATA_PIN, STRIP_0_CLOCK_PIN, RGB>(leds_hd, NUM_LEDS);
63 FastLED.addLeds<APA102, STRIP_1_DATA_PIN, STRIP_1_CLOCK_PIN, RGB>(leds, NUM_LEDS);
64}
65
66uint8_t wrap_8bit(int i) {
67 // Module % operator here wraps a large "i" so that it is
68 // always in [0, 255] range when returned. For example, if
69 // "i" is 256, then this will return 0. If "i" is 257
70 // then this will return 1. No matter how big the "i" is, the
71 // output range will always be [0, 255]
72 return i % 256;
73}
74
75void loop() {
76 // Draw a a linear ramp of brightnesses to showcase the difference between
77 // the HD and non-HD mode.
78 for (int i = 0; i < NUM_LEDS; i++) {
79 uint8_t brightness = map(i, 0, NUM_LEDS - 1, 0, 255);
80 CRGB c(brightness, brightness, brightness); // Just make a shade of white.
81 leds_hd[i] = c; // The APA102HD leds do their own gamma correction.
82 CRGB c_gamma_corrected = software_gamma(c);
83 leds[i] = c_gamma_corrected; // Set the software gamma corrected
84 // values to the other strip.
85 }
86 FastLED.show(); // All leds are now written out.
87 delay(8); // Wait 8 milliseconds until the next frame.
88}
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:45
central include file for FastLED, defines the CFastLED class/object
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:106
@ APA102
APA102 LED chipset.
Definition FastLED.h:101
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:94
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:79
@ RGB
Red, Green, Blue (0012)
Definition eorder.h:15
LIB8STATIC uint8_t dim8_raw(uint8_t x)
Adjust a scaling value for dimming.
Definition scale8.h:703
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54
uint8_t r
Red channel value.
Definition crgb.h:58
uint8_t g
Green channel value.
Definition crgb.h:62
uint8_t b
Blue channel value.
Definition crgb.h:66