Created
December 22, 2014 02:31
-
-
Save bitchwhocodes/1b3297bd3dbf7be93f72 to your computer and use it in GitHub Desktop.
Arduino NeoPixels Animation without using Delay
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 <Adafruit_NeoPixel.h> | |
#define NUM_PIXELS 60 | |
unsigned long interval=50; // the time we need to wait | |
unsigned long previousMillis=0; | |
uint32_t currentColor;// current Color in case we need it | |
uint16_t currentPixel = 0;// what pixel are we operating on | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, 6, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
currentColor = strip.Color(255,0,0); | |
currentPixel = 0; | |
strip.begin(); | |
strip.show(); // Initialize all pixels to 'off' | |
} | |
// Basic idea. You could reorg and pass pixel index and color as a function - or you could go through a gradient of colors. | |
void loop(){ | |
if ((unsigned long)(millis() - previousMillis) >= interval) { | |
previousMillis = millis(); | |
colorWipe(); | |
} | |
} | |
void colorWipe(){ | |
strip.setPixelColor(currentPixel,currentColor); | |
strip.show(); | |
currentPixel++; | |
if(currentPixel == NUM_PIXELS){ | |
currentPixel = 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An excellent example. How to use this example to smooth off the LEDs?