Skip to content

Instantly share code, notes, and snippets.

@unbibium
Last active August 29, 2015 14:10
Show Gist options
  • Save unbibium/d620859c8d4276ebb64b to your computer and use it in GitHub Desktop.
Save unbibium/d620859c8d4276ebb64b to your computer and use it in GitHub Desktop.
Interlaced scrolling with NeoPixel+Arduino proof of concept
// Proof of concept for using horizontal interlacing with scrolling text to improve resolution.
#include <Adafruit_GFX.h>
#include <gamma.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#define PIN 6
#define ROWS 6
#define COLUMNS 22
// number of pixels to skip, use -1 for no interlacing.
#define SKIP -2
#define WAIT 10w
// matrix instead
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(COLUMNS, ROWS, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
// raw data for scroll. later versions will have text and a font
uint32_t onColor = matrix.Color(60, 40, 20);
uint32_t offColor = matrix.Color(0, 0, 15);
const byte idea[] = {
0b00111100,
0b00111110,
0b00010011,
0b00010011,
0b00111110,
0b00111100,
0,0,
0b00111111,
0b00111111,
0b00100101,
0b00100101,
0b00111111,
0b00011010,
0,0,
0b00011110,
0b00111111,
0b00100001,
0b00100001,
0b00110011,
0b00010010,
0,0,
0b00111111,
0b00111111,
0b00100001,
0b00110011,
0b00011110,
0b00001100,
0,0,
0b00010010,
0b00111010,
0b00101010,
0b00101010,
0b00111110,
0b00111100,
0,0,
0b00111111,
0b00111111,
0b00100100,
0b00100100,
0b00111100,
0b00011000,
0,0,
0b00011100,
0b00111110,
0b00100010,
0b00100010,
0b00100010,
0b00100010,
0,0,
0b00011000,
0b00111100,
0b00100100,
0b00100100,
0b00111111,
0b00111111,
0,0,
};
// 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.
void setup() {
matrix.begin();
matrix.show();
}
void loop() {
for( int sourceColumn = 0; sourceColumn < sizeof(idea); sourceColumn++) {
int renderSource = sourceColumn;
for( int renderColumn = 0; renderColumn < COLUMNS; renderColumn++ ) {
renderSource = (renderSource + SKIP) % sizeof(idea);
renderByteAtColumn( idea[renderSource], renderColumn );
}
matrix.show();
delay(WAIT);
}
}
// TODO: replace this method with the proper matrix call.
int pixelLocation(int col, int row) {
if( row & 1 ) {
return (row+1) * COLUMNS - (col +1 );
} else {
return row * COLUMNS + col;
}
}
void renderByteAtColumn( byte pixels, int column ) {
for(int row=0; row<ROWS; row++) {
int location = pixelLocation( column, row );
if( pixels & ( 1 << row) ) {
matrix.setPixelColor(location, onColor);
} else {
matrix.setPixelColor(location, offColor);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment