arduino/gemma_fire_v2/gemma_fire_v2.ino
Martin Donnelly c06d3c6f09 updated gemma
2018-11-29 17:27:01 +00:00

152 lines
5.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>
#include <string.h>
#define PIN 0
#define FIRE_SIZE 15
#define RED_SIZE 12
#define LIGHTNING_SIZE 14
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, PIN);
uint8_t mode = 0, // Current animation effect
offset = 0; // Position of spinny eyes
uint32_t color = 0xffffff; // Start red
uint32_t prevTime;
uint32_t prevChange;
uint8_t m = 0;
uint32_t waiting = 8000;
uint32_t changeTime = 120000;
uint8_t colourMode = 0;
const uint32_t mix[] = { 0xff00ff, 0x8f00ff, 0xf000ff };
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, 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 }; // ,0xc2fffe, , , , , , , , , , };
const uint32_t reds[] = { 0xf4c262, 0xff6961 , 0xff5c5c, 0xff1c00, 0xff0800, 0xff0000, 0xcd5c5c, 0xe34234, 0xd73b3e, 0xce1620, 0xcc0000, 0xb22222 }; //, , , , , , , , , , , 0xb31b1b};
const uint32_t clu_red_yellow[] = { 0xff0000, 0xff1100, 0xff2200, 0xff3300, 0xff4400, 0xff5500, 0xff6600, 0xff7700, 0xff8800, 0xff9900, 0xffaa00, 0xffbb00, 0xffcc00, 0xffdd00, 0xffee00, 0xffff00 };
const uint32_t clu_blue_red[] = {0x0000ff, 0x2200ff, 0x4400ff, 0x6600ff, 0x8800ff, 0xaa00ff, 0xcc00ff, 0xee00ff, 0xff00ee, 0xff00cc, 0xff00aa, 0xff0088, 0xff0066, 0xff0044, 0xff0022, 0xff0000};
const uint32_t clu_teal_purple[] = {0x00ffff, 0x00ddff, 0x00bbff, 0x0099ff, 0x0077ff, 0x0055ff, 0x0033ff, 0x0011ff, 0x1100ff, 0x3300ff, 0x5500ff, 0x7700ff, 0x9900ff, 0xbb00ff, 0xdd00ff, 0xff00ff};
const uint32_t clu_red_orange[] = { 0xff0000, 0xff0c00, 0xff1700, 0xff2300, 0xff2f00, 0xff3a00, 0xff4600, 0xff5200, 0xff5d00, 0xff6900, 0xff7500, 0xff8000, 0xff8c00, 0xff9800, 0xffa300, 0xffaf00 };
const uint32_t clu_teal_blue[] = { 0x00ffff, 0x00eeff, 0x00ddff, 0x00ccff, 0x00bbff, 0x00aaff, 0x0099ff, 0x0088ff, 0x0077ff, 0x0066ff, 0x0055ff, 0x0044ff, 0x0033ff, 0x0022ff, 0x0011ff, 0x0000ff };
const uint32_t clu_red_black[] = { 0xff0000, 0xee0000, 0xdd0000, 0xcc0000, 0xbb0000, 0xaa0000, 0x990000, 0x880000, 0x770000, 0x660000, 0x550000, 0x440000, 0x330000, 0x220000, 0x080000, 0x000000 };
const uint32_t clu_purple_yellow[] = { 0xff00ff, 0xff00dd, 0xff00bb, 0xff0099, 0xff0077, 0xff0055, 0xff0033, 0xff0011, 0xff1100, 0xff3300, 0xff5500, 0xff7700, 0xff9900, 0xffbb00, 0xffdd00, 0xffff00};
const uint32_t clu_yellow_green[] = { 0xffff00, 0xeeff00, 0xddff00, 0xccff00, 0xbbff00, 0xaaff00, 0x99ff00, 0x88ff00, 0x77ff00, 0x66ff00, 0x55ff00, 0x44ff00, 0x33ff00, 0x22ff00, 0x11ff00, 0x00ff00 };
const uint32_t clu_orange_green[] = { 0xff5300, 0xff6f00, 0xff8c00, 0xffa800, 0xffc500, 0xffe100, 0xfffe00, 0xe4ff00, 0xc7ff00, 0xabff00, 0x8eff00, 0x72ff00, 0x55ff00, 0x39ff00, 0x1cff00, 0x00ff00 };
const uint32_t breathe_cols[] = { 0xff0000, 0xffff00, 0x00ffff, 0xff00ff, 0xffffff };
void setup() {
pixels.begin();
pixels.setBrightness(10); // 1/3 brightness
prevTime = millis();
prevChange = 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!
//
pixels.setPixelColor(0, color);
pixels.show();
delay(1000);
break;
case 1: // Spinny wheels (8 LEDs on at a time)
B = breathe[m];
// color = fire[random(FIRE_SIZE)];
// color = lightning[random(LIGHTNING_SIZE)];
color = breathe_cols[colourMode];
pixels.setPixelColor(0, color);
pixels.setBrightness(B);
pixels.show();
m++;
if (m > 49) {
m = 0;
}
delay(60);
break;
case 2:
if (colourMode == 0) {
color = clu_red_yellow[random(FIRE_SIZE)];
}
if (colourMode == 1) {
color = clu_blue_red[random(FIRE_SIZE)];
}
if (colourMode == 2) {
color = clu_teal_purple[random(FIRE_SIZE)];
}
if (colourMode == 3) {
color = clu_red_orange[random(FIRE_SIZE)];
}
if (colourMode == 4) {
color = lightning[random(FIRE_SIZE)];
}
pixels.setPixelColor(0, color);
pixels.show();
delay(120);
break;
}
t = millis();
if ((t - prevTime) > waiting) {
// color = fire[random(FIRE_SIZE)];
mode++;
m = 0;
if (mode > 2) {
mode = 0;
}
switch (mode) {
case 0:
waiting = 8000;
color = color = breathe_cols[colourMode];
break;
case 1:
waiting = 30000;
break;
case 2:
waiting = 30000;
pixels.setBrightness(60);
break;
}
if (mode == 2) {
++colourMode;
if (colourMode > 4) {
colourMode = 0;
}
}
//color = rgb[random(3)];
prevTime = millis();
}
}