forked from marmilicious/FastLED_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththree_moving_colors.ino
54 lines (40 loc) · 1.75 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
//***************************************************************
// Three moving colors.
//
// Marc Miller, Jan. 2019
// April 2019 - Updated to use EVERY_N instead of delay().
//***************************************************************
#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];
int16_t positionRed = NUM_LEDS*2/3; // Set initial start position of Red
int16_t positionWhite = NUM_LEDS/3; // Set initial start position of White
int16_t positionBlue = 0; // Set initial start position of Blue
#define holdTime 120 // Milliseconds to hold position before advancing
int8_t delta = 1; // 1 or -1. Sets forward or backwards 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) {
//set position and color of pixels
leds[(positionRed + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Red;
leds[(positionWhite + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Grey;
leds[(positionBlue + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Blue;
FastLED.show(); //show the pixels
//advance position based on delta, and rollover if needed.
positionRed = ((positionRed + delta + NUM_LEDS) % NUM_LEDS);
positionWhite = ((positionWhite + delta + NUM_LEDS) % NUM_LEDS);
positionBlue = ((positionBlue + delta + NUM_LEDS) % NUM_LEDS);
}//end_every_n
}//end_main_loop