54 lines
1.4 KiB
Arduino
54 lines
1.4 KiB
Arduino
#include <FastLED.h>
|
|
|
|
// How many leds in your strip?
|
|
#define NUM_LEDS 240
|
|
#define BASE_LEDS 60
|
|
|
|
// For led chips like Neopixels, which have a data line, ground, and power, you just
|
|
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
|
|
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
|
|
#define DATA_PIN 14
|
|
#define CLOCK_PIN 13
|
|
|
|
// Define the array of leds
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
void setup() {
|
|
Serial.begin(57600);
|
|
Serial.println("resetting");
|
|
FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
|
|
FastLED.setBrightness(84);
|
|
}
|
|
|
|
// Sets LED i and all its mirrored positions:
|
|
// i, 120-i, 120+i, 180-i, 180+i
|
|
void setMirroredLED(int i, CHSV color) {
|
|
leds[i] = color;
|
|
if (120 - i >= 0 && 120 - i < NUM_LEDS) leds[119 - i] = color;
|
|
if (120 + i < NUM_LEDS) leds[120 + i] = color;
|
|
if (180 + i < NUM_LEDS) leds[240 - i] = color;
|
|
}
|
|
|
|
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
|
|
|
|
void loop() {
|
|
static uint8_t hue = 0;
|
|
Serial.print("x");
|
|
// First slide the led in one direction
|
|
for(int i = 0; i < BASE_LEDS; i++) {
|
|
setMirroredLED(i, CHSV(hue++, 255, 255));
|
|
FastLED.show();
|
|
fadeall();
|
|
delay(10);
|
|
}
|
|
Serial.print("x");
|
|
|
|
// Now go in the other direction.
|
|
for(int i = (BASE_LEDS)-1; i >= 0; i--) {
|
|
setMirroredLED(i, CHSV(hue++, 255, 255));
|
|
FastLED.show();
|
|
fadeall();
|
|
delay(10);
|
|
}
|
|
}
|