arduino/gemma_pixel/gemma_pixel.ino
2018-11-03 20:21:33 +00:00

70 lines
1.8 KiB
C++

// Low power NeoPixel earrings example. Makes a nice blinky display
// with just a few LEDs on at any time...uses MUCH less juice than
// rainbow display!
#include <Adafruit_NeoPixel.h>
#define PIN 0
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);
uint8_t mode = 0, // Current animation effect
offset = 0; // Position of spinny eyes
uint32_t color = 0xffae00; // Start red
uint32_t prevTime;
uint8_t maxPixels = 2;
const uint32_t mm[] = { 0xff2426, 0xfe3223, 0xfe4121, 0xfd4f1f, 0xfd5e1d, 0xfc6d1b, 0xfc7b18, 0xfb8a16, 0xfb9814, 0xfaa712, 0xfab610, 0xffc20d, 0xffd30b, 0xffe309, 0xfff407, 0xf7ff05 };
void setup() {
pixels.begin();
pixels.setBrightness(60); // 1/3 brightness
prevTime = millis();
}
void loop() {
uint8_t i;
uint32_t t;
switch(mode) {
case 0: // Random sparks - just one LED on at a time!
i = random(15);
color = mm[i];
pixels.setPixelColor(0, color);
pixels.setPixelColor(1, color);
pixels.show();
i = random(4);
delay(5 + (i*5));
pixels.setPixelColor(0, 0);
pixels.setPixelColor(1, 0);
pixels.show();
break;
case 1: // Spinny wheels (8 LEDs on at a time)
for(i=0; i<maxPixels; i++) {
uint32_t c = 0;
if(((offset + i) & 7) < 2) c = color; // 4 pixels on...
pixels.setPixelColor( i, c); // First eye
pixels.setPixelColor(31-i, c); // Second eye (flipped)
}
pixels.show();
offset++;
delay(20);
break;
}
t = millis();
if((t - prevTime) > 8000) { // Every 8 seconds...
mode++; // Next mode
if(mode > 1) { // End of modes?
mode = 0; // Start modes over
color >>= 8; // Next color R->G->B
if(!color) color = 0xffae00; // Reset to red
}
for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
prevTime = t;
}
}