Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Last active April 12, 2021 21:33
Show Gist options
  • Save cbscribe/2e84b27eb9c42d50cd70159bf31c01d1 to your computer and use it in GitHub Desktop.
Save cbscribe/2e84b27eb9c42d50cd70159bf31c01d1 to your computer and use it in GitHub Desktop.
Arduino NeoPIxel Examples
#include <Adafruit_NeoPixel.h>
# define PIN 2
# define NUM_PIXELS 6
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIN);
void setup()
{
pixels.begin();
}
void loop()
{
int val = analogRead(A5);
val = map(val, 0, 1023, 0, NUM_PIXELS-1);
for (int i=0; i<NUM_PIXELS; i++)
{
if (i <= val)
{
pixels.setPixelColor(i, 0, 255, 0);
}
else
{
pixels.setPixelColor(i, 0, 0, 0);
}
}
pixels.show();
delay(100);
}
#include <Adafruit_NeoPixel.h>
# define PIN 2
# define NUM_PIXELS 12
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIN);
void setup()
{
pixels.begin();
// pixels.setPixelColor(0, 255, 128, 0);
// fill -> color, start, count
// pixels.fill(pixels.Color(255, 128, 0), 1, 4);
// pixels.show();
}
void loop()
{
for (int i=0; i<NUM_PIXELS; i++)
{
pixels.setPixelColor(i, 255, 255, 0);
pixels.show();
delay(100);
}
pixels.clear();
pixels.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment