Skip to content

Instantly share code, notes, and snippets.

@imerr
Created February 22, 2017 09:36
Show Gist options
  • Save imerr/8965383f02391ecd00957abe2dbaa786 to your computer and use it in GitHub Desktop.
Save imerr/8965383f02391ecd00957abe2dbaa786 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define NEOPIXEL_COUNT 4
#define NEOPIXEL_PIN 4
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
unsigned int rgbColor[] {255, 0, 0};
int decColor = 0;
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
if (rgbColor[decColor] == 0) {
decColor++;
if (decColor == 3) decColor=0;
}
int incColor = decColor == 2 ? 0 : decColor + 1;
rgbColor[decColor] -= 1;
rgbColor[incColor] += 1;
for (uint8_t u = 0; u < NEOPIXEL_COUNT; u++)
{
pixels.setPixelColor(u, pixels.Color(rgbColor[0], rgbColor[1], rgbColor[2])); // Moderately bright green color.
}
pixels.show();
delay(5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment