Skip to content

Instantly share code, notes, and snippets.

@atuline
Last active January 25, 2023 08:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atuline/552e53f3079ff89abe3dfa4410f0d465 to your computer and use it in GitHub Desktop.
Save atuline/552e53f3079ff89abe3dfa4410f0d465 to your computer and use it in GitHub Desktop.
/* Increase/decrease brigtness of LED's.
*
* By: Andrew Tuline
*
* Date: Mar 21, 2019
*
* This is a way to increase the brighness of LED's.
*
*
*/
#include "FastLED.h" // FastLED library.
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
// Fixed definitions cannot change on the fly.
#define LED_DT 12 // Data pin to connect to the strip.
#define LED_CK 11 // Clock pin for WS2801 or APA102.
#define COLOR_ORDER BGR // It's GRB for WS2812 and BGR for APA102.
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit.
#define NUM_LEDS 40 // Number of LED's.
// Global variables can be changed on the fly.
uint8_t max_bright = 255; // Overall brightness.
struct CHSV ledshsv[NUM_LEDS]; // Initialize our CHSV reference array.
struct CRGB leds[NUM_LEDS]; // This is what we are displaying.
struct CRGB ledscrgb[NUM_LEDS]; // Initialize our CRGB reference array.
void setup() {
Serial.begin(57600); // Initialize serial port for debugging.
delay(1000); // Soft startup.
LEDS.addLeds<LED_TYPE,LED_DT,LED_CK,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // Use this for WS2801 or APA102
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(0xFFB0F0); // Use this for WS2812
FastLED.setBrightness(max_bright);
set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA.
ledshsv[0] = CHSV(32,255,255); // Set it to orange as based on https://github.com/FastLED/FastLED/wiki/Pixel-reference
ledscrgb[3] = CRGB::Purple;
} // setup()
void loop () {
uint8_t beatval = beatsin8(20,0,255);
ledshsv[0].val = beatval; // Options are .hue, .sat, .val. I don't like this method as .val goes from 0 to 255,
// whereas the original .val may not have been that bright.
hsv2rgb_rainbow(ledshsv, leds, NUM_LEDS); // This will convert and copy over the entire CHSV defined array to 'leds'.
leds[3]= ledscrgb[3]; // In this case, I'm just copying over a single pixel from ledscrgb to 'leds'.
// memmove(ledscrgb, leds, NUM_LEDS*3); // You could copy the entire CRGB array.
leds[3].nscale8_video(beatval); // Then I'll scale the copied value from 0 to 100%. This is a better method in my opinion.
FastLED.show();
} // loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment