-
Notifications
You must be signed in to change notification settings - Fork 46
/
beat8.ino
58 lines (44 loc) · 1.66 KB
/
beat8.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//***************************************************************
// beat8 example. Moves pixel position based on beat8.
//
// -Marc Miller, Jan 2016
// Updated Feb 2016 - made move speed and fade rate variables.
//***************************************************************
#include "FastLED.h"
#define LED_TYPE LPD8806
#define DATA_PIN 11
#define CLOCK_PIN 13
#define NUM_LEDS 32
#define COLOR_ORDER GRB
#define BRIGHTNESS 50
CRGB leds[NUM_LEDS];
uint8_t gHue = 0; // Used to cycle through rainbow.
uint8_t moveSpeed = 6; // Higher value moves pixel faster.
uint8_t fadeRate = 80; // Use lower value to give a fading tail.
//---------------------------------------------------------------
void setup()
{
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(3000); // 3 second delay
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
//---------------------------------------------------------------
void loop()
{
EVERY_N_MILLISECONDS( 50 ) { gHue++; } // Slowly cycle through the rainbow
beat8_tail(); // Subroutine to move the pixel!
FastLED.show(); // Display the pixels.
}//end main loop
//===============================================================
void beat8_tail()
{
EVERY_N_MILLISECONDS( 5 ) {
fadeToBlackBy( leds, NUM_LEDS, fadeRate); // Fade out pixels.
}
uint16_t pos = beat8(moveSpeed) % NUM_LEDS; // modulo the position to be within NUM_LEDS
leds[pos] = CHSV( gHue, 200, 255);
//Serial.print("pos: "); Serial.println(pos);
}
//---------------------------------------------------------------
//EOF