NeoPixel Animaties

Wil je dingen doen met neopixels? Hier heb je een handige set functies!

#include <Adafruit_NeoPixel.h>

#define PixelPin    5
#define NUMPIXELS   10

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PixelPin , NEO_GRB + NEO_KHZ800);

// Plaats dit boven void Setup(); */
int ledState = LOW;           
unsigned long previousMillis = 0;  



void setup() {
  pixels.begin();
  pixels.show();
}

void loop(){
  FlashAll(pixels.Color(10, 0, 10), pixels.Color(0, 10, 10), 1000);
  //SetFixedColor(pixels.Color(0, 50, 0));
}

void SetFixedColor (uint32_t c1) {
  for (int i = 0; i < NUMPIXELS; i++) {
    pixels.setPixelColor(i, c1);
    pixels.show();
  }
}

void FlashAll(uint32_t c1, uint32_t c2, int interval) {
  
    unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;
      SetFixedColor(c1);
    } else {
      ledState = LOW;
      SetFixedColor(c2);
    }
  }
}