Skip to content

Instantly share code, notes, and snippets.

@bitchwhocodes
Created December 22, 2014 02:31
Show Gist options
  • Save bitchwhocodes/1b3297bd3dbf7be93f72 to your computer and use it in GitHub Desktop.
Save bitchwhocodes/1b3297bd3dbf7be93f72 to your computer and use it in GitHub Desktop.
Arduino NeoPixels Animation without using Delay
#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;
}
@dimRG
Copy link

dimRG commented Nov 17, 2016

An excellent example. How to use this example to smooth off the LEDs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment