Created
January 29, 2019 15:08
-
-
Save milesburton/6711807a63fd060337960ced636019b8 to your computer and use it in GitHub Desktop.
ESP8266 with Neopixels example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FastLED.h> | |
// How many leds in your strip? | |
#define NUM_LEDS 30 | |
#define DATA_PIN 8 | |
CRGB leds[NUM_LEDS]; | |
void setup() { | |
Serial.begin(57600); | |
Serial.println("resetting"); | |
LEDS.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); | |
LEDS.setBrightness(84); | |
} | |
void fadeall() { | |
for (int i = 0; i < NUM_LEDS; i++) { | |
leds[i].nscale8(250); | |
} | |
} | |
void loop() { | |
static uint8_t hue = 0; | |
Serial.print("x"); | |
for (int y = 0; y < 10; y++) { | |
// First slide the led in one direction | |
for (int i = 0; i < NUM_LEDS / 2; i++) { | |
// Set the i'th led to red | |
leds[i] = CHSV(hue++, 255, 255); | |
leds[NUM_LEDS - i] = CHSV(hue++, 255, 255); | |
if ( random8() < 30) { | |
leds[ random16(NUM_LEDS) ] += CRGB::White; | |
} | |
// Show the leds | |
FastLED.show(); | |
// now that we've shown the leds, reset the i'th led to black | |
// leds[i] = CRGB::Black; | |
fadeall(); | |
// Wait a little bit before we loop around and do it again | |
delay(35); | |
} | |
Serial.print("x"); | |
} | |
for (int y = 0; y < 10; y++) { | |
// First slide the led in one direction | |
for (int i = (NUM_LEDS) - 1; i >= 0; i--) { | |
// Set the i'th led to red | |
leds[i] = CHSV(hue++, 255, 255); | |
leds[NUM_LEDS - i] = CHSV(hue++, 255, 255); | |
if ( random8() < 30) { | |
leds[ random16(NUM_LEDS) ] += CRGB::White; | |
} | |
// Show the leds | |
FastLED.show(); | |
// now that we've shown the leds, reset the i'th led to black | |
// leds[i] = CRGB::Black; | |
fadeall(); | |
// Wait a little bit before we loop around and do it again | |
delay(35); | |
} | |
Serial.print("x"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment