Skip to content

Instantly share code, notes, and snippets.

@kliph
Last active August 29, 2015 14:06
Show Gist options
  • Save kliph/4301f4dc16c43a3b8f9f to your computer and use it in GitHub Desktop.
Save kliph/4301f4dc16c43a3b8f9f to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
// 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 strip1 = Adafruit_NeoPixel(2, 5, NEO_GRB + NEO_KHZ800);
int pixel1 = 0;
int pixel2 = 1;
// int pixel3 = 2;
// int pixel4 = 3;
int potScale = 4; // Scale from ~1020 to 255 because
// potentiometers send a signal that
// is larger than the brightness
// values that setPixelColor expects.
int pixelColorR = 255;
int pixelColorG = 255;
int pixelColorB = 40;
void setPixelColor(uint16_t n,
uint8_t r,
uint8_t g,
uint8_t b,
uint16_t brightness) {
strip1.setPixelColor(n,
brightness * r / 255,
brightness * g / 255,
brightness * b / 255);
}
void setup() {
strip1.begin();
strip1.show(); // Initialize all pixels to 'off'
}
void loop() {
int potValue1 = analogRead(0)/potScale;
int potValue2 = analogRead(1)/potScale;
// int potValue3 = analogRead(2)/potScale;
// int potValue4 = analogRead(3)/potScale;
// set the color for the Pixels:
setPixelColor(pixel1, pixelColorR, pixelColorG, pixelColorB, potValue1);
setPixelColor(pixel2, pixelColorR, pixelColorG, pixelColorB, potValue2);
// setPixelColor(pixel3, pixelColorR, pixelColorG, pixelColorB, potValue3);
// setPixelColor(pixel4, pixelColorR, pixelColorG, pixelColorB, potValue4);
// Send the pixel values.
strip1.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment