Skip to content

Instantly share code, notes, and snippets.

@mjdargen
Created October 9, 2020 13:49
Show Gist options
  • Save mjdargen/36d1d145815927d9dd16c9cee4097f88 to your computer and use it in GitHub Desktop.
Save mjdargen/36d1d145815927d9dd16c9cee4097f88 to your computer and use it in GitHub Desktop.
/*
Create new file called images.h.
Copy the Arduino/C code variables to the right of the matrix picture.
Paste the code into the images.h file
https://github.com/xantorohara/led-matrix-editor
http://xantorohara.github.io/led-matrix-editor/
https://xantorohara.github.io/led-matrix-editor/#003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|00007e99997e0000|000000ffff000000|000000ffff000000|00007e99997e0000|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|00007e99997e0000|000000ffff000000|000000ffff000000|00007e99997e0000|003c429999423c00|003c429999423c00|00007e99997e0000|000000ffff000000|000000ffff000000|00007e99997e0000
*/
#include <LedControl.h>
#include "images.h"
#define BRIGHTNESS 10
#define DELAY 100
#define DIN_PIN 7
#define CS_PIN_1 6
#define CS_PIN_2 4
#define CLK_PIN 5
//#define NO_DUPLICATE 1
LedControl matrix1 = LedControl(DIN_PIN, CLK_PIN, CS_PIN_1);
#ifdef NO_DUPLICATE
LedControl matrix2 = LedControl(DIN_PIN, CLK_PIN, CS_PIN_2);
#endif
int count1 = 0;
int count2 = 0;
void setup() {
// configure first matrix
matrix1.clearDisplay(0);
matrix1.shutdown(0, false);
matrix1.setIntensity(0, BRIGHTNESS);
// configure second matrix
#ifdef NO_DUPLICATE
matrix2.clearDisplay(0);
matrix2.shutdown(0, false);
matrix2.setIntensity(0, BRIGHTNESS);
#endif
}
void loop() {
displayImage(matrix1, IMAGES[count1]);
if (++count1 >= IMAGES_LEN ) count1 = 0;
#ifdef NO_DUPLICATE
displayImage(matrix2, IMAGES2[count2]);
if (++count2 >= IMAGES2_LEN ) count2 = 0;
#endif
delay(DELAY);
}
void displayImage(LedControl matrix, uint64_t image) {
for (int i = 0; i < 8; i++) {
byte row = (image >> i * 8) & 0xFF;
for (int j = 0; j < 8; j++) {
matrix.setLed(0, i, j, bitRead(row, j));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment