-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy paththree_moving_colors.ino
60 lines (46 loc) · 1.78 KB
/
three_moving_colors.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
59
60
//***************************************************************
// Three moving colors.
// Uses modulo, %, to make pixel position "loop" around and
// stay in valid pixel range.
//
// Marc Miller, Jan. 2019
// Apr. 2019 - updated to use EVERY_N instead of delay()
// Apr. 2021 - cleaned up some duplicate code
//***************************************************************
#include "FastLED.h"
#define LED_TYPE LPD8806
#define DATA_PIN 11
#define CLOCK_PIN 13
#define NUM_LEDS 32
#define COLOR_ORDER GRB
#define MASTER_BRIGHTNESS 64
CRGB leds[NUM_LEDS];
// Set initial start position of each color
int16_t positionA = NUM_LEDS*2/3;
int16_t positionB = NUM_LEDS/3;
int16_t positionC = 0;
const uint16_t holdTime = 120; // Adjusts speed of travel
int8_t delta = 1; // 1 or -1. Sets travel direction
//---------------------------------------------------------------
void setup() {
delay(1500); // Startup delay
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
//FastLED.addLeds<LED_TYPE,DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(MASTER_BRIGHTNESS);
}
//---------------------------------------------------------------
void loop() {
EVERY_N_MILLISECONDS(holdTime) {
// Fading tail effect. Comment out for solid colors
fadeToBlackBy( leds, NUM_LEDS, 100);
// assign pixel colors
leds[positionA] = CRGB::Red;
leds[positionB] = CRGB::Grey; // Using grey so not as bright
leds[positionC] = CRGB::Blue;
FastLED.show(); // Show the pixels
// Advance position based on delta, and rollover if needed.
positionA = ((positionA + delta + NUM_LEDS) % NUM_LEDS);
positionB = ((positionB + delta + NUM_LEDS) % NUM_LEDS);
positionC = ((positionC + delta + NUM_LEDS) % NUM_LEDS);
}//end every_n
}