forked from marmilicious/FastLED_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
three_moving_pixels_v3.ino
68 lines (54 loc) · 2.53 KB
/
three_moving_pixels_v3.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
61
62
63
64
65
66
67
68
//***************************************************************
// Three moving pixels example
// Uses modulo, %, to make pixel position "loop" around and
// stay in valid pixel range.
//
// Marc Miller, Feb 2015. Updated Jan 2016.
//***************************************************************
#include "FastLED.h"
#define LED_TYPE NEOPIXEL // Strip type: NEOPIXEL, APA102, LPD8806, etc.
#define DATA_PIN 6
//#define CLOCK_PIN 13
#define NUM_LEDS 12
//#define COLOR_ORDER BGR
#define MASTER_BRIGHTNESS 100 // Master brightness (Range is 0-255)
CRGB leds[NUM_LEDS];
int16_t positionRed = 0; // Set initial start position of Red pixel
int16_t positionWhite = 4; // Set initial start position of White pixel
int16_t positionBlue = 8; // Set initial start position of Blue pixel
int8_t delta = 1; // Using a negative value will move pixels backwards.
uint16_t holdTime = 1000; // Milliseconds to hold position before advancing
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check your baud rate)
delay(3000); // Startup delay
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLOCK_PIN>,COLOR_ORDER,(leds, NUM_LEDS); // ***For strips using Clock.
FastLED.addLeds<LED_TYPE,DATA_PIN>(leds, NUM_LEDS); // ***For Clock-less strips.
FastLED.setBrightness(MASTER_BRIGHTNESS);
}
//---------------------------------------------------------------
void loop() { // START MAIN LOOP
EVERY_N_MILLISECONDS(holdTime) {
// Set pixel color
leds[positionRed] = CRGB::Red;
leds[positionWhite] = CRGB::White;
leds[positionBlue] = CRGB::Blue;
// Show the pixels
FastLED.show();
//delay(holdTime); // Delay for a bit.
// Set pixels back to Black for the next loop around.
leds[positionRed] = CRGB::Black;
leds[positionWhite] = CRGB::Black;
leds[positionBlue] = CRGB::Black;
// Set new position, moving (forward or backward) by delta.
// NUM_LEDS is added to the position before doing the modulo
// to cover cases where delta is a negative value.
positionRed = (positionRed + delta + NUM_LEDS) % NUM_LEDS;
positionWhite = (positionWhite + delta + NUM_LEDS) % NUM_LEDS;
positionBlue = (positionBlue + delta + NUM_LEDS) % NUM_LEDS;
// Print out position values to see what's happening.
//Serial.print("pos R = "); Serial.print(positionRed);
//Serial.print("\t pos W = "); Serial.print(positionWhite);
//Serial.print("\t pos B = "); Serial.println(positionBlue);
}
} // END MAIN LOOP