Skip to content

Instantly share code, notes, and snippets.

@atuline
Last active April 24, 2018 08:52
Show Gist options
  • Save atuline/89021f1f5355e9aeac37b6854be5028a to your computer and use it in GitHub Desktop.
Save atuline/89021f1f5355e9aeac37b6854be5028a to your computer and use it in GitHub Desktop.
/* Simple dot
*
* By: Andrew Tuline
*
* Date: July, 2015
*
* Similar to dots by John Burroughs, but uses the FastLED beatsin8() function instead.
*
*/
#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 // Serial data pin
#define LED_CK 11 // Serial clock pin for APA102 or WS2801
#define COLOR_ORDER BGR // It's GRB for WS2812B
#define LED_TYPE APA102 // What kind of strip are you using (APA102, WS2801 or WS@2812B
#define NUM_LEDS 60 // Number of LED's
// Initialize changeable global variables.
uint8_t max_bright = 255; // Overall brightness definition. It can be changed on the fly.
struct CRGB leds[NUM_LEDS]; // Initialize our LED array.
// Define variables used by the sequences.
uint8_t fadeval = 224; // Trail behind the LED's. Lower => faster fade.
uint8_t bpm = 30;
void setup() {
delay(1000); // Power-up safety delay or something like that.
Serial.begin(57600);
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812B
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for APA102 or WS2801
FastLED.setBrightness(max_bright);
set_max_power_in_volts_and_milliamps(5, 500);
} // setup()
void loop () {
dot_beat();
FastLED.show();
} // loop()
void dot_beat() {
uint8_t outer = beatsin8(bpm, 0, NUM_LEDS-1); // Move entire length
leds[outer] = CRGB::Red;
nscale8(leds,NUM_LEDS,fadeval); // Fade the entire array. Or for just a few LED's, use nscale8(&leds[2], 5, fadeval);
} // dot_beat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment