Skip to content

Instantly share code, notes, and snippets.

@chrwei
Last active February 15, 2019 15:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrwei/526bba507f69017b6ad8270a6110cf73 to your computer and use it in GitHub Desktop.
Save chrwei/526bba507f69017b6ad8270a6110cf73 to your computer and use it in GitHub Desktop.
// action shot https://i.imgur.com/kpAiXTV.gifv
#include <Adafruit_NeoPixel.h>
#define N_LEDS 60
#define PIN 8
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
//brightness jumpers
pinMode(2, INPUT_PULLUP); //25%
pinMode(3, INPUT_PULLUP); //50%
pinMode(4, INPUT_PULLUP); //100%
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
int posR = 0, dirR = 1, interR=25; // Position, direction of "eye"
int posG = 30, dirG = 1, interG=47; // Position, direction of "eye"
long lastMillisR = 0, lastMillisG = 0;
void loop() {
int j;
setBright();
if (lastMillisR + interR <= millis()) {
for(j=-3; j<= 3; j++) strip.setPixelColor(posR+j, 0);
// Bounce off ends of strip
posR += dirR;
if(posR < 0) {
posR = 1;
dirR = -dirR;
} else if(posR >= strip.numPixels()) {
posR = strip.numPixels() - 3;
dirR = -dirR;
}
strip.setPixelColor(posR - 3, 0x040000); // Darker red
strip.setPixelColor(posR - 2, 0x100000); // Dark red
strip.setPixelColor(posR - 1, 0x800000); // Medium red
strip.setPixelColor(posR , 0xFF3000); // Center pixel is brightest
strip.setPixelColor(posR + 1, 0x800000); // Medium red
strip.setPixelColor(posR + 2, 0x100000); // Dark red
strip.setPixelColor(posR + 3, 0x040000); // Darker red
lastMillisR = millis();
strip.show();
}
if (lastMillisG + interG <= millis()) {
for(j=-3; j<= 3; j++) strip.setPixelColor(posG+j, 0);
// Bounce off ends of strip
posG += dirG;
if(posG < 0) {
posG = 1;
dirG = -dirG;
} else if(posG >= strip.numPixels()) {
posG = strip.numPixels() - 3;
dirG = -dirG;
}
strip.setPixelColor(posG - 3, 0x000400); // Darker green
strip.setPixelColor(posG - 2, 0x001000); // Dark green
strip.setPixelColor(posG - 1, 0x008000); // Medium green
strip.setPixelColor(posG , 0x00FF30); // Center pixel is brightest
strip.setPixelColor(posG + 1, 0x008000); // Medium green
strip.setPixelColor(posG + 2, 0x001000); // Dark green
strip.setPixelColor(posG + 3, 0x000400); // Darker green
lastMillisG = millis();
strip.show();
}
}
void setBright() {
if(digitalRead(2) == LOW) {
strip.setBrightness(64); //25% of 255
return;
}
if(digitalRead(3) == LOW) {
strip.setBrightness(128); //50% of 255
return;
}
if(digitalRead(4) == LOW) {
strip.setBrightness(255); //100% of 255
return;
}
//neither are low
strip.setBrightness(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment