Last active
May 8, 2016 08:03
-
-
Save fpt/87835d3802650e580b923d5c33f30d5c to your computer and use it in GitHub Desktop.
Adafruit NeoPixel cyclic color 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
// | |
// For more detail, see tutorial below: | |
// https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library | |
// | |
#include <Adafruit_NeoPixel.h> | |
// Arduino Pin No. | |
#define PIN 6 | |
// Parameter 1 = number of pixels in strip | |
// Parameter 2 = pin number (most are valid) | |
// Parameter 3 = pixel type flags, add together as needed: | |
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) | |
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) | |
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) | |
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, PIN, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
strip.begin(); | |
strip.show(); // Initialize all pixels to 'off' | |
} | |
int t = 0; | |
int tcol(int t, int span) { | |
span = (span + 1) * 500; | |
float sig = sin(t * 3.14159 / float(span)) / 2.0 + .5; | |
sig = sig * sig; | |
return int(sig * 255) % 256; | |
} | |
void loop() { | |
int n = strip.numPixels(); | |
for (int i = 0; i < n; i++) { | |
strip.setPixelColor(i, tcol(t, i % 3), tcol(t, (i + 1) % 3), tcol(t, (i + 2) % 3)); | |
} | |
strip.show(); | |
t++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment