FastLED 3.9.13
Loading...
Searching...
No Matches
HD107.ino
Go to the documentation of this file.
1
5
6#include <Arduino.h>
7#include <FastLED.h>
8#include <lib8tion.h>
9
10#define NUM_LEDS 20
11// uint8_t DATA_PIN, uint8_t CLOCK_PIN,
12
13#define STRIP_0_DATA_PIN 1
14#define STRIP_0_CLOCK_PIN 2
15#define STRIP_1_DATA_PIN 3
16#define STRIP_1_CLOCK_PIN 4
17
18
19CRGB leds_hd[NUM_LEDS] = {0}; // HD mode implies gamma.
20CRGB leds[NUM_LEDS] = {0}; // Software gamma mode.
21
22// This is the regular gamma correction function that we used to have
23// to do. It's used here to showcase the difference between HD107HD
24// mode which does the gamma correction for you.
25CRGB software_gamma(const CRGB& in) {
26 CRGB out;
27 // dim8_raw are the old gamma correction functions.
28 out.r = dim8_raw(in.r);
29 out.g = dim8_raw(in.g);
30 out.b = dim8_raw(in.b);
31 return out;
32}
33
34void setup() {
35 delay(500); // power-up safety delay
36 // Two strips of LEDs, one in HD mode, one in software gamma mode.
37 FastLED.addLeds<HD107HD, STRIP_0_DATA_PIN, STRIP_0_CLOCK_PIN, RGB>(leds_hd, NUM_LEDS);
38 FastLED.addLeds<HD107, STRIP_1_DATA_PIN, STRIP_1_CLOCK_PIN, RGB>(leds, NUM_LEDS);
39}
40
41uint8_t wrap_8bit(int i) {
42 // Module % operator here wraps a large "i" so that it is
43 // always in [0, 255] range when returned. For example, if
44 // "i" is 256, then this will return 0. If "i" is 257
45 // then this will return 1. No matter how big the "i" is, the
46 // output range will always be [0, 255]
47 return i % 256;
48}
49
50void loop() {
51 // Draw a a linear ramp of brightnesses to showcase the difference between
52 // the HD and non-HD mode.
53 for (int i = 0; i < NUM_LEDS; i++) {
54 uint8_t brightness = map(i, 0, NUM_LEDS - 1, 0, 255);
55 CRGB c(brightness, brightness, brightness); // Just make a shade of white.
56 leds_hd[i] = c; // The HD107HD leds do their own gamma correction.
57 CRGB c_gamma_corrected = software_gamma(c);
58 leds[i] = c_gamma_corrected; // Set the software gamma corrected
59 // values to the other strip.
60 }
61 FastLED.show(); // All leds are now written out.
62 delay(8); // Wait 8 milliseconds until the next frame.
63}
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:57
central include file for FastLED, defines the CFastLED class/object
@ HD107HD
Same as APA102, but in turbo 40-mhz mode.
Definition FastLED.h:108
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:106
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:91
@ 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