Skip to content

Instantly share code, notes, and snippets.

@jkeefe
Created March 22, 2020 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkeefe/c7ec245edd8f06d53dfe873ba8769cba to your computer and use it in GitHub Desktop.
Save jkeefe/c7ec245edd8f06d53dfe873ba8769cba to your computer and use it in GitHub Desktop.
Fish tank code (see johnkeefe.net)
#include <Adafruit_NeoPixel.h>
#define PIN1 6
#define PIN2 3
#define NUM_LEDS 60
#define BRIGHTNESS 250
int blue_every = 12; // make every Xth pixel blue
int red_every = 4; // make every Xth pixel red
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN1, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS, PIN2, NEO_GRBW + NEO_KHZ800);
void setup() {
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip2.setBrightness(BRIGHTNESS);
strip2.begin();
strip2.show(); // Initialize all pixels to 'off'
light_the_tank();
}
void loop() {
// DO NOTHING
}
void light_the_tank() {
for(uint16_t i=0; i<strip.numPixels(); i++) {
if (i % blue_every == 1) {
// shift the blues so they don't collide with the reds
strip.setPixelColor(i, strip.Color(0,0,255,0) );
strip2.setPixelColor(i, strip.Color(0,0,255,0) );
}
else if (i % red_every == 0) {
strip.setPixelColor(i, strip.Color(255,0,0,0) );
strip2.setPixelColor(i, strip.Color(255,0,0,0) );
}
else {
strip.setPixelColor(i, strip.Color(0,0,0, 255 ) );
strip2.setPixelColor(i, strip.Color(0,0,0, 255 ) );
}
}
strip.show();
strip2.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment