-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneopixel_flames.ino
65 lines (53 loc) · 2.04 KB
/
neopixel_flames.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 5
// The overall fire brightness
// (this can affect both color levels and power consumption)
int brightness = 128;
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(29, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
// For the ultimate NeoPixel guide, check out:
// https://learn.adafruit.com/adafruit-neopixel-uberguide/overview
void setup() {
strip.begin();
strip.setBrightness(brightness);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Uncomment one of these RGB (Red, Green, Blue) values to
// set the base color of the flame. The color will flickr
// based on the initial base color
// Regular (orange) flame:
int r = 226, g = 121, b = 35;
// Purple flame:
// int r = 158, g = 8, b = 148;
// Green flame:
//int r = 74, g = 150, b = 12;
// Flicker, based on our initial RGB values
for(int i=0; i<strip.numPixels(); i++) {
int flicker = random(0,55);
int r1 = r-flicker;
int g1 = g-flicker;
int b1 = b-flicker;
if(g1<0) g1=0;
if(r1<0) r1=0;
if(b1<0) b1=0;
strip.setPixelColor(i,r1,g1, b1);
}
strip.show();
// Adjust the delay here, if you'd like. Right now, it randomizes the
// color switch delay to give a sense of realism
delay(random(10,113));
}