Last active
April 12, 2021 21:33
-
-
Save cbscribe/2e84b27eb9c42d50cd70159bf31c01d1 to your computer and use it in GitHub Desktop.
Arduino NeoPIxel Examples
This file contains hidden or 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
#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); | |
} |
This file contains hidden or 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
#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