Skip to content

Commit eccf466

Browse files
committed
🚨 pattern print
1 parent 402084b commit eccf466

2 files changed

Lines changed: 134 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ These files require specific hardware to function. Until I have a proper README
1111

1212
* Arduino Uno R3
1313
* AdaFruit NeoPixel 12-LED ring
14-
* AdaFruit NeoPixel 8x8 64 RGB LED NeoMatrix
14+
* AdaFruit NeoPixel 8x8 NeoMatrix
15+
* AdaFruit NeoPixel 1x8 Stick
1516
* Standard breadboard + wires
1617

neopixel-1x8-patternprint.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
var pixel = require("node-pixel");
2+
var five = require("johnny-five");
3+
var colorwheel = require("./_utils.js").colorwheel;
4+
5+
var board = new five.Board();
6+
var strip = null;
7+
var colorShift = 0;
8+
9+
board.on("ready", function() {
10+
console.log("board.ready");
11+
12+
var led = new five.Led(10);
13+
led.brightness(48);
14+
15+
var shift = 2; // how fast the colors rotate, 0-255
16+
var fps = 1; // how often to refresh per second, ~300 is max
17+
18+
const NUM_ROWS = 8;
19+
const NUM_COLS = 1;
20+
21+
strip = new pixel.Strip({
22+
board: this,
23+
controller: "FIRMATA",
24+
strips: [ {pin: 6, length: NUM_ROWS*NUM_COLS}, ],
25+
gamma: 2.2, // 3.6 = night, 2.6 = bright day
26+
});
27+
28+
strip.on("ready", function() {
29+
strip.off();
30+
console.log("👍 strip.ready with " + strip.length + " LEDs");
31+
loop(fps);
32+
});
33+
34+
// setting this up so the syntax highlighter works to our advantage in the
35+
// patterns below.
36+
var X = true;
37+
38+
// Patterns are defined in rows of arrays. Each row can be as long as you
39+
// want, but they should all be the same length.
40+
var pattern1 = [
41+
// HELLO, WORLD!!!
42+
[0,0,0,0,0,0,0,X,X,0,0,X,X,0,0,X,X,X,X,X,0,0,X,X,0,0,0,0,0,X,X,0,0,0,0,0,X,X,X,X,X,X,0,0,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
var pattern = pattern2;
76+
77+
// Set the display color by adjusting RGB values here. The highest value found
78+
// in your `pattern` array informs you how high these numbers may be.
79+
//
80+
// use 100 as a high value
81+
var color = {
82+
red: 150,
83+
green: 50,
84+
blue: 25,
85+
}
86+
87+
function loop(framerate) {
88+
var loop = setInterval(function() {
89+
// determine length of pattern
90+
var messageLength = pattern[0].length;
91+
92+
// cycle through all patterns
93+
for (var currentFrame = 0; currentFrame < messageLength - NUM_COLS; currentFrame++) {
94+
for (var row = 0; row < pattern.length; row++) {
95+
for (var col = currentFrame; col < currentFrame + NUM_COLS; col++) {
96+
var thisPixel = (NUM_COLS*row) + col - currentFrame;
97+
// COLOR: use "greyscale" values for one hue via `colors` object
98+
// 'rgb(' + Math.round(pattern[row][col] * color.red) + ',' + Math.round(pattern[row][col] * color.green) + ',' + Math.round(pattern[row][col] * color.blue) + ')'
99+
100+
// COLOR: use color wheel
101+
// colorwheel(thisPixel * (255/strip.length) + Math.round(colorShift))
102+
103+
// draw new pixel.
104+
if (pattern[row][col]) {
105+
strip.pixel(thisPixel).color(colorwheel(thisPixel * (255/strip.length) + Math.round(colorShift)));
106+
} else {
107+
strip.pixel(thisPixel).off();
108+
}
109+
}
110+
111+
// shift colors
112+
colorShift += shift;
113+
}
114+
115+
// update strip
116+
strip.show();
117+
}
118+
}, 1000 / framerate);
119+
}
120+
121+
// go nuts!
122+
this.repl.inject({
123+
strip: strip,
124+
led: led
125+
});
126+
127+
// cleanup when this program is terminated
128+
this.on("exit", function() {
129+
led.off();
130+
strip.off(); // doesn't work, not sure why
131+
});
132+
});

0 commit comments

Comments
 (0)