Skip to content

Instantly share code, notes, and snippets.

@MaBecker
Created January 15, 2018 22:04
Show Gist options
  • Save MaBecker/b7a7bf082274b69c53a8b92b5d7b85e4 to your computer and use it in GitHub Desktop.
Save MaBecker/b7a7bf082274b69c53a8b92b5d7b85e4 to your computer and use it in GitHub Desktop.
Scroll String on 3 x 8x8 neopixel panel
// scrollString.js
// tested on ESP8266 12F
var pin = D4;
// connected to three neopixel plate (x,y)=(0-7,0-23)
var leds = Graphics.createArrayBuffer(8,24,24);
leds.setRotation(1,false);
leds.flip = function(){require("neopixel").write(pin,leds.buffer);};
leds.off = function(){leds.clear();leds.flip();};
// right to left
function scrollString(scroll) {
if ( !scroll.active ) {
clearTimeout(timer);
leds.off();
}
else {
if ( scroll.xpos !== -1*scroll.len ) {
timer=setTimeout(function(scroll){scrollString(scroll);},scroll.delay_scroll,scroll);
leds.clear();
leds.setColor(scroll.color.blue,scroll.color.red,scroll.color.green);
leds.drawString(scroll.text,scroll.xpos,scroll.ypos);
// setTimeout('leds.flip();',scroll.delay_flip);
leds.flip();
scroll.xpos--;
}
else {
scroll.xpos=leds.getWidth();
scrollString(scroll);
}
}
}
var s1 = {
text : "Espruino rocks",
len : 56, // using 4x6font
xpos : leds.getWidth(), // offset x
ypos : 1, // ofset y
delay_scroll : 300, // time delay for scroll
color : { red:0,green:0.2,blue:0.2},
active : true, // false will stop scrolling
};
leds.off();
leds.setColor(0,0,0);
scrollString(s1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment