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

130 lines
3.2 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 = 1, // Current animation effect
offset = 0; // Position of spinny eyes
uint32_t color = 0xff0000; // Start red
uint32_t prevTime;
uint8_t m;
const float pi = 3.14;
const uint32_t breathe[] = {7, 7, 15, 23, 30, 38, 45, 52, 58, 64, 70, 76, 80, 85, 89, 92, 95, 97, 98, 99, 100, 100, 100, 100, 100, 100, 99, 98, 97, 95, 92, 89, 85, 80, 76, 70, 64, 58, 52, 45, 38, 30, 23, 15, 7 };
const uint32_t fire[] = { 0xff2426, 0xfe3223, 0xfe4121, 0xfd4f1f, 0xfd5e1d, 0xfc6d1b, 0xfc7b18, 0xfb8a16, 0xfb9814, 0xfaa712, 0xfab610, 0xffc20d, 0xffd30b, 0xffe309, 0xfff407, 0xf7ff05 };
const uint32_t lightning[] = { 0xffffff, 0x2436ff, 0x2e43fe, 0x3950fe, 0x4354fe, 0x4e6bfe,0xffffff, 0x5879fe, 0x6386fe, 0x6d93fe, 0x78a1fe, 0x82aefe, 0x8dbcfe, 0x97c9fe, 0xa2d6fe, 0xace4fe, 0xb7f1fe, 0xc2fffe, 0xffffff};
void setup() {
pixels.begin();
pixels.setBrightness(60); // 1/3 brightness
prevTime = millis();
}
void loop() {
uint8_t i;
uint32_t t;
uint8_t B;
switch(mode) {
case 0: // Random sparks - just one LED on at a time!
i = 0;
pixels.setPixelColor(i, color);
pixels.show();
delay(10);
// pixels.setPixelColor(i, 0);
break;
case 1: // Spinny wheels (8 LEDs on at a time)
// B = breathe[m];
color = 0xff2426;
pixels.setPixelColor(i, color);
// pixels.setBrightness(B);
pixels.show();
m++;
if (m > 44) {
m = 0;
//color = 0xff00ff;
}
delay(60);
break;
case 2:
i = 0;
B = random(30) + 30;
color = fire[random(15)];
pixels.setPixelColor(i, color);
pixels.setBrightness(B);
pixels.show();
delay(40);
// pixels.setPixelColor(i, 0);
break;
case 3:
// i = random(32);
i = 0;
color = lightning[random(18)];
pixels.setPixelColor(i, color);
pixels.show();
delay(40);
pixels.setPixelColor(i, 0);
break;
/* case 4: // Spinny wheels (8 LEDs on at a time)
for(i=0; i<7; i++) {
uint32_t c = 0;
if(((offset + i) & 7) < 2) c = fire[i+1]; // 4 pixels on...
pixels.setPixelColor( i, c); // First eye
// pixels.setPixelColor(31-i, c); // Second eye (flipped)
}
pixels.show();
offset++;
delay(50);*/
break;
case 5: // Spinny wheels (8 LEDs on at a time)
if (m > 17) m = 0;
uint32_t c = lightning[m];
for (i=0;i<7; i=i+2) {
pixels.setPixelColor( i, lightning[m-1]); // First eye
}
for (i=1;i<7; i=i+2) {
pixels.setPixelColor( i, fire[m-1]); // First eye
}
pixels.show();
m++;
delay(50);
break;
}
t = millis();
/*
*
if((t - prevTime) > 8000) { // Every 8 seconds...
mode++; // Next mode
m = 0;
if(mode > 3) { // 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;
}
*/
}