Skip to content

Commit a3c3b1f

Browse files
javastraatjavastraat
javastraat
authored and
javastraat
committed
initial upload
1 parent 43926d1 commit a3c3b1f

File tree

3,643 files changed

+539108
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,643 files changed

+539108
-0
lines changed

Adafruit_NeoPixel/Adafruit_NeoPixel.cpp

Lines changed: 916 additions & 0 deletions
Large diffs are not rendered by default.

Adafruit_NeoPixel/Adafruit_NeoPixel.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*--------------------------------------------------------------------
2+
This file is part of the Adafruit NeoPixel library.
3+
4+
NeoPixel is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as
6+
published by the Free Software Foundation, either version 3 of
7+
the License, or (at your option) any later version.
8+
9+
NeoPixel is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with NeoPixel. If not, see
16+
<http://www.gnu.org/licenses/>.
17+
--------------------------------------------------------------------*/
18+
19+
#ifndef ADAFRUIT_NEOPIXEL_H
20+
#define ADAFRUIT_NEOPIXEL_H
21+
22+
#if (ARDUINO >= 100)
23+
#include <Arduino.h>
24+
#else
25+
#include <WProgram.h>
26+
#include <pins_arduino.h>
27+
#endif
28+
29+
// 'type' flags for LED pixels (third parameter to constructor):
30+
#define NEO_RGB 0x00 // Wired for RGB data order
31+
#define NEO_GRB 0x01 // Wired for GRB data order
32+
#define NEO_COLMASK 0x01
33+
#define NEO_KHZ400 0x00 // 400 KHz datastream
34+
#define NEO_KHZ800 0x02 // 800 KHz datastream
35+
#define NEO_SPDMASK 0x02
36+
37+
class Adafruit_NeoPixel {
38+
39+
public:
40+
41+
// Constructor: number of LEDs, pin number, LED type
42+
Adafruit_NeoPixel(uint16_t n, uint8_t p=6, uint8_t t=NEO_GRB + NEO_KHZ800);
43+
44+
void
45+
begin(void),
46+
show(void),
47+
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
48+
setPixelColor(uint16_t n, uint32_t c),
49+
setBrightness(uint8_t);
50+
uint16_t
51+
numPixels(void);
52+
static uint32_t
53+
Color(uint8_t r, uint8_t g, uint8_t b);
54+
uint32_t
55+
getPixelColor(uint16_t n);
56+
57+
private:
58+
59+
const uint16_t
60+
numLEDs, // Number of RGB LEDs in strip
61+
numBytes; // Size of 'pixels' buffer below
62+
const uint8_t
63+
pin, // Output pin number
64+
type; // Pixel flags (400 vs 800 KHz, RGB vs GRB color)
65+
uint8_t
66+
brightness,
67+
*pixels; // Holds LED color values (3 bytes each)
68+
uint32_t
69+
endTime; // Latch timing reference
70+
#ifdef __AVR__
71+
const volatile uint8_t
72+
*port; // Output PORT register
73+
const uint8_t
74+
pinMask; // Output PORT bitmask
75+
#endif
76+
77+
};
78+
79+
#endif // ADAFRUIT_NEOPIXEL_H

Adafruit_NeoPixel/COPYING

Lines changed: 794 additions & 0 deletions
Large diffs are not rendered by default.

Adafruit_NeoPixel/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Adafruit NeoPixel library
2+
=========================
3+
4+
Arduino library for controlling single-wire-based LED pixels and strip such as the [Adafruit 60 LED/meter Digital LED strip][strip], the [Adafruit FLORA RGB Smart Pixel][flora], the [Adafruit Breadboard-friendly RGB Smart Pixel][pixel], the [Adafruit NeoPixel Stick][stick], and the [Adafruit NeoPixel Shield][shield].
5+
6+
After downloading, rename folder to 'Adafruit_NeoPixel' and install in Arduino Libraries folder. Restart Arduino IDE, then open File->Sketchbook->Library->Adafruit_NeoPixel->strandtest sketch.
7+
8+
[flora]: http://adafruit.com/products/1060
9+
[strip]: http://adafruit.com/products/1138
10+
[pixel]: http://adafruit.com/products/1312
11+
[stick]: http://adafruit.com/products/1426
12+
[shield]: http://adafruit.com/products/1430

Adafruit_NeoPixel/colorcodes.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
//define colors
3+
#define black 0,0,0
4+
#define blue 0,0,255
5+
#define cyan 0,255,255
6+
#define gray 128,128,128
7+
#define green 0,128,0
8+
#define lime 0,255,0
9+
#define magenta 255,0,255
10+
#define maroon 128,0,0
11+
#define navy 0,0,128
12+
#define olive 128,128,0
13+
#define purple 128,0,128
14+
#define red 255,0,0
15+
#define silver 192,192,192
16+
#define teal 0,128,128
17+
#define white 255,255,255
18+
#define yellow 255,255,0
19+
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
/*
2+
NeoPixel Ring goggles sketch -- for steampunk, rave or Burning Man fashion!
3+
Welding or costume goggles using 50mm round lenses can be outfitted with
4+
a pair of Adafruit NeoPixel Rings: http://www.adafruit.com/product/1463
5+
6+
Please exercise common sense. These goggles emit a LOT of stray light and
7+
should NOT BE WORN ON YOUR EYES. They're for fashion and costuming only,
8+
for display on a hat or on your forehead.
9+
10+
Draws a spinning rainbow on both eyepieces. Not a Mac beachball, honest.
11+
"Eyes" glance around and blink at random.
12+
13+
For 'reflected' colors (rainbows rotate in opposite directions, while eyes
14+
look in same direction), connect the output of the first ring to the input
15+
of the second. Or you can connect the inputs of both rings to the same
16+
Arduino pin if that's easier -- the rainbows will both twirl in the same
17+
direction in that case.
18+
19+
By default, pixel #0 (the first LED) on both rings should be at the TOP of
20+
the goggles. Looking at the BACK of the board, pixel #0 is immediately
21+
clockwise from the OUT connection. If a different pixel is at the top,
22+
that's OK, the code can compensate (TOP_LED_FIRST and TOP_LED_SECOND below).
23+
*/
24+
25+
#include <Adafruit_NeoPixel.h>
26+
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
27+
#include <avr/power.h>
28+
#endif
29+
30+
#define PIN 4
31+
32+
#define TOP_LED_FIRST 0 // Change these if the first pixel is not
33+
#define TOP_LED_SECOND 0 // at the top of the first and/or second ring.
34+
35+
#define EFFECT RAINBOW // Choose a visual effect from the names below
36+
37+
#define RAINBOW 0
38+
#define ECTO 1
39+
40+
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);
41+
42+
const int8_t PROGMEM
43+
yCoord[] = { // Vertical coordinate of each pixel. First pixel is at top.
44+
127,117,90,49,0,-49,-90,-117,-127,-117,-90,-49,0,49,90,117 },
45+
sine[] = { // Brightness table for ecto effect
46+
0, 28, 96, 164, 192, 164, 96, 28, 0, 28, 96, 164, 192, 164, 96, 28 };
47+
48+
// Eyelid vertical coordinates. Eyes shut slightly below center.
49+
#define upperLidTop 130
50+
#define upperLidBottom -45
51+
#define lowerLidTop -40
52+
#define lowerLidBottom -130
53+
54+
// Gamma correction improves appearance of midrange colors
55+
const uint8_t PROGMEM gamma8[] = {
56+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57+
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
58+
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
59+
3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7,
60+
7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12,
61+
13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20,
62+
20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29,
63+
30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42,
64+
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
65+
58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 75,
66+
76, 77, 78, 80, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96,
67+
97, 99,100,102,103,105,106,108,109,111,112,114,115,117,119,120,
68+
122,124,125,127,129,130,132,134,136,137,139,141,143,145,146,148,
69+
150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,
70+
182,184,186,188,191,193,195,197,199,202,204,206,209,211,213,215,
71+
218,220,223,225,227,230,232,235,237,240,242,245,247,250,252,255
72+
};
73+
74+
uint32_t
75+
iColor[16][3]; // Background colors for eyes
76+
int16_t
77+
hue = 0; // Initial hue around perimeter (0-1535)
78+
uint8_t
79+
iBrightness[16], // Brightness map -- eye colors get scaled by these
80+
brightness = 220, // Global brightness (0-255)
81+
blinkFrames = 5, // Speed of current blink
82+
blinkCounter = 30, // Countdown to end of next blink
83+
eyePos = 192, // Current 'resting' eye (pupil) position
84+
newEyePos = 192, // Next eye position when in motion
85+
gazeCounter = 75, // Countdown to next eye movement
86+
gazeFrames = 50; // Duration of eye movement (smaller = faster)
87+
int8_t
88+
eyeMotion = 0; // Distance from prior to new position
89+
90+
91+
void setup() {
92+
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
93+
if(F_CPU == 16000000) clock_prescale_set(clock_div_1);
94+
// Seed random number generator from an unused analog input:
95+
randomSeed(analogRead(2));
96+
#else
97+
randomSeed(analogRead(A0));
98+
#endif
99+
100+
pixels.begin();
101+
}
102+
103+
void loop() {
104+
uint8_t i, r, g, b, a, c, inner, outer, ep;
105+
int y1, y2, y3, y4, h;
106+
int8_t y;
107+
108+
// Draw eye background colors
109+
110+
#if EFFECT == RAINBOW
111+
112+
// This renders a glotating rainbow...a WAY overdone LED effect but
113+
// does show the color gamut nicely.
114+
115+
for(h=hue, i=0; i<16; i++, h += 96) {
116+
a = h;
117+
switch((h >> 8) % 6) {
118+
case 0: iColor[i][0] = 255; iColor[i][1] = a; iColor[i][2] = 0; break;
119+
case 1: iColor[i][0] = ~a; iColor[i][1] = 255; iColor[i][2] = 0; break;
120+
case 2: iColor[i][0] = 0; iColor[i][1] = 255; iColor[i][2] = a; break;
121+
case 3: iColor[i][0] = 0; iColor[i][1] = ~a; iColor[i][2] = 255; break;
122+
case 4: iColor[i][0] = a; iColor[i][1] = 0; iColor[i][2] = 255; break;
123+
case 5: iColor[i][0] = 255; iColor[i][1] = 0; iColor[i][2] = ~a; break;
124+
}
125+
}
126+
hue += 7;
127+
if(hue >= 1536) hue -= 1536;
128+
129+
#elif EFFECT == ECTO
130+
131+
// A steampunk aesthetic might fare better with this more subdued effect.
132+
// Etherial green glow with just a little animation for visual spice.
133+
134+
a = (hue >> 4) & 15;
135+
c = hue & 15;
136+
for(i=0; i<16; i++) {
137+
b = (a + 1) & 15;
138+
iColor[i][1] = 255; // Predominantly green
139+
iColor[i][0] = (pgm_read_byte(&sine[a]) * (16 - c) +
140+
pgm_read_byte(&sine[b]) * c ) >> 4;
141+
iColor[i][2] = iColor[i][0] >> 1;
142+
a = b;
143+
}
144+
hue -= 3;
145+
146+
#endif
147+
148+
// Render current blink (if any) into brightness map
149+
if(blinkCounter <= blinkFrames * 2) { // In mid-blink?
150+
if(blinkCounter > blinkFrames) { // Eye closing
151+
outer = blinkFrames * 2 - blinkCounter;
152+
inner = outer + 1;
153+
} else { // Eye opening
154+
inner = blinkCounter;
155+
outer = inner - 1;
156+
}
157+
y1 = upperLidTop - (upperLidTop - upperLidBottom) * outer / blinkFrames;
158+
y2 = upperLidTop - (upperLidTop - upperLidBottom) * inner / blinkFrames;
159+
y3 = lowerLidBottom + (lowerLidTop - lowerLidBottom) * inner / blinkFrames;
160+
y4 = lowerLidBottom + (lowerLidTop - lowerLidBottom) * outer / blinkFrames;
161+
for(i=0; i<16; i++) {
162+
y = pgm_read_byte(&yCoord[i]);
163+
if(y > y1) { // Above top lid
164+
iBrightness[i] = 0;
165+
} else if(y > y2) { // Blur edge of top lid in motion
166+
iBrightness[i] = brightness * (y1 - y) / (y1 - y2);
167+
} else if(y > y3) { // In eye
168+
iBrightness[i] = brightness;
169+
} else if(y > y4) { // Blur edge of bottom lid in motion
170+
iBrightness[i] = brightness * (y - y4) / (y3 - y4);
171+
} else { // Below bottom lid
172+
iBrightness[i] = 0;
173+
}
174+
}
175+
} else { // Not in blink -- set all 'on'
176+
memset(iBrightness, brightness, sizeof(iBrightness));
177+
}
178+
179+
if(--blinkCounter == 0) { // Init next blink?
180+
blinkFrames = random(4, 8);
181+
blinkCounter = blinkFrames * 2 + random(5, 180);
182+
}
183+
184+
// Calculate current eye movement, possibly init next one
185+
if(--gazeCounter <= gazeFrames) { // Is pupil in motion?
186+
ep = newEyePos - eyeMotion * gazeCounter / gazeFrames; // Current pos.
187+
if(gazeCounter == 0) { // Last frame?
188+
eyePos = newEyePos; // Current position = new pos
189+
newEyePos = random(16) * 16; // New pos. (always pixel center)
190+
eyeMotion = newEyePos - eyePos; // Distance to move
191+
gazeFrames = random(10, 20); // Duration of movement
192+
gazeCounter = random(gazeFrames, 130); // Count to END of next movement
193+
}
194+
} else ep = eyePos; // Not moving -- fixed gaze
195+
196+
// Draw pupil -- 2 pixels wide, but sup-pixel positioning may span 3.
197+
a = ep >> 4; // First candidate
198+
b = (a + 1) & 0x0F; // 1 pixel CCW of a
199+
c = (a + 2) & 0x0F; // 2 pixels CCW of a
200+
i = ep & 0x0F; // Fraction of 'c' covered (0-15)
201+
iBrightness[a] = (iBrightness[a] * i ) >> 4;
202+
iBrightness[b] = 0;
203+
iBrightness[c] = (iBrightness[c] * (16 - i)) >> 4;
204+
205+
// Merge iColor with iBrightness, issue to NeoPixels
206+
for(i=0; i<16; i++) {
207+
a = iBrightness[i] + 1;
208+
// First eye
209+
r = iColor[i][0]; // Initial background RGB color
210+
g = iColor[i][1];
211+
b = iColor[i][2];
212+
if(a) {
213+
r = (r * a) >> 8; // Scale by brightness map
214+
g = (g * a) >> 8;
215+
b = (b * a) >> 8;
216+
}
217+
pixels.setPixelColor(((i + TOP_LED_FIRST) & 15),
218+
pgm_read_byte(&gamma8[r]), // Gamma correct and set pixel
219+
pgm_read_byte(&gamma8[g]),
220+
pgm_read_byte(&gamma8[b]));
221+
222+
// Second eye uses the same colors, but reflected horizontally.
223+
// The same brightness map is used, but not reflected (same left/right)
224+
r = iColor[15 - i][0];
225+
g = iColor[15 - i][1];
226+
b = iColor[15 - i][2];
227+
if(a) {
228+
r = (r * a) >> 8;
229+
g = (g * a) >> 8;
230+
b = (b * a) >> 8;
231+
}
232+
pixels.setPixelColor(16 + ((i + TOP_LED_SECOND) & 15),
233+
pgm_read_byte(&gamma8[r]),
234+
pgm_read_byte(&gamma8[g]),
235+
pgm_read_byte(&gamma8[b]));
236+
}
237+
pixels.show();
238+
239+
delay(15);
240+
}
241+

0 commit comments

Comments
 (0)