Skip to content

Instantly share code, notes, and snippets.

@bmidgley
Last active February 19, 2018 16:24
Show Gist options
  • Save bmidgley/1cff45b057b8edd02da80dedbce2358c to your computer and use it in GitHub Desktop.
Save bmidgley/1cff45b057b8edd02da80dedbce2358c to your computer and use it in GitHub Desktop.
Lightblue bean neopixel ring animated
#include <Adafruit_NeoPixel.h>
// The pin that is connected to the NeoPixels
#define PIN 5
// The amount of LEDs in the NeoPixels
#define NUMPIXELS 16
// previousLedColor will be used to check if the LED's color has changed
LedReading previousLedColor;
// Set up the NeoPixel library
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize the NeoPixels
pixels.begin();
// Program the Bean to wake up when connected from the "Lightblue" iOS app
Bean.enableWakeOnConnect(true);
}
void loop() {
LedReading ledColor;
unsigned long int c;
if(Bean.getConnectionState()) {
// store the end-of-ring value we are about to overwrite
c = pixels.getPixelColor(NUMPIXELS-1);
// shift the colors over one cell
for(int i=NUMPIXELS-1; i>0; i-=1) {
pixels.setPixelColor(i, pixels.getPixelColor(i-1));
}
// Get the values from the Bean's onboard LED, set by the iOS app
ledColor = Bean.getLed();
if(ledColor.red != previousLedColor.red || ledColor.green != previousLedColor.green || ledColor.blue != previousLedColor.blue) {
// If the color has changed, use that in the new location and remember it
pixels.setPixelColor(0, pixels.Color(ledColor.red, ledColor.green, ledColor.blue));
previousLedColor = ledColor;
} else {
// otherwise, use the previous value and dim it a little bit
pixels.setPixelColor(0, pixels.Color(((c>>16)&255)/2,((c>>8)&255)/2,((c)&255)/2));
}
pixels.show();
} else {
// Sleep unless woken
Bean.sleep(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment