Skip to content

Instantly share code, notes, and snippets.

@masha256
Created November 14, 2017 20:51
Show Gist options
  • Save masha256/19796d505553f59d2bd91fe9128a2b7d to your computer and use it in GitHub Desktop.
Save masha256/19796d505553f59d2bd91fe9128a2b7d to your computer and use it in GitHub Desktop.
makerhq ledboard example
#include <Arduino.h>
#include <Adafruit_NeoMatrix.h>
#define BOARD_WIDTH 10
#define BOARD_HEIGHT 20
#define ROWS_PER_GROUP 4
#define NEO_PIN 7
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(BOARD_WIDTH,
BOARD_HEIGHT,
NEO_PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS,
NEO_GRB + NEO_KHZ800);
uint16_t xyToPixel(uint16_t x, uint16_t y) {
int row_in_group = y%ROWS_PER_GROUP;
uint16_t pixel = 0;
switch(row_in_group) {
case 0:
pixel = y * BOARD_WIDTH + x;
break;
case 1:
pixel = (y+1) * BOARD_WIDTH + x;
break;
case 2:
pixel = (y * BOARD_WIDTH - x) - 1;
break;
case 3:
pixel = ((y+1) * BOARD_WIDTH) - x - 1;
break;
}
#ifdef TOP_DOWN
return (BOARD_WIDTH * BOARD_HEIGHT) - pixel - 1;
#else
return pixel;
#endif
}
void setup() {
matrix.begin();
matrix.show();
matrix.setRemapFunction(xyToPixel);
}
void loop() {
matrix.clear();
for (int y = 0; y < BOARD_HEIGHT; y++) {
for (int x = 0; x < BOARD_WIDTH; x++) {
matrix.drawPixel(x, y, matrix.Color(255, 0, 0));
matrix.show();
delay(100);
}
}
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment