Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// LED Matrix: https://www.amazon.com/gp/product/B01EJ1AFW8
- /// Install the MD_MAX72xx v2.10.00 and TimerOne liberty for the Arduino Uno R3.
- /// Credits go to those who did all the hard work at http://www.housedillon.com/?p=1272
- //
- //VIDEO here: https://youtu.be/OlV-Urn8THE
- #include <TimerOne.h>
- #define HEIGHT 8
- #define WIDTH 32 //64
- #define HEIGHTR 32 //64
- #define WIDTHR 8 //16
- #define ROWCHANGE 4 //Rows change direction every X rows //default is 4
- #define INVERT 0 //LEDs will be lit in reverse order resulting in more LED active at once //default is 0
- #define MOVEDELAY 200 //How much delay should there be before the rows move //default is 200 (131)
- byte row = 0;
- // Program to exercise the MD_MAX72XX library
- //
- // Uses most of the functions in the library
- #include <MD_MAX72xx.h> //You'll need to #define USE_FC16_HW as 1 and USE_PAROLA_HW as 0
- #include <SPI.h>
- #define MAX_DEVICES 4
- #define CLK_PIN 13 // or SCK
- #define DATA_PIN 11 // or MOSI
- #define CS_PIN 10 // or SS
- // SPI hardware interface
- MD_MAX72XX mx = MD_MAX72XX(CS_PIN, MAX_DEVICES);
- // Arbitrary pins
- // MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
- //=== S E T U P ===
- void setup() {
- //pinMode(led, OUTPUT);
- mx.begin();
- mx.control(MD_MAX72XX::INTENSITY, 10); //How brite should the LEDs be 1 to 10
- //Turn all LEDs on then turn them off
- mx.control(MD_MAX72XX::TEST, MD_MAX72XX::ON);
- delay(500);
- mx.control(MD_MAX72XX::TEST, MD_MAX72XX::OFF);
- }
- //=== L O O P ===
- void loop() {
- cm5();
- }
- void HardwarePlot(int x, int y, int z)
- {
- if (z == INVERT) {
- mx.setPoint(y, x, true);
- } else {
- mx.setPoint(y, x, false);
- }
- }
- long long array[2][16];
- byte getPixel(byte x, byte y, byte whichArray) {
- unsigned long long temp = (1ULL << y);
- if (array[whichArray][x] & temp) {
- return 1; //the yth bit was set, so return 1.
- }
- else {
- return 0; //the yth bit was clear, so return 0;
- }
- }
- void setPixel(byte x, byte y, byte whichArray, byte pixel) {
- unsigned long long temp = (1ULL << y);
- if (pixel) {
- array[whichArray][x] |= temp;
- }
- else {
- array[whichArray][x] &= ~temp;
- }
- }
- void clearArray(byte no) {
- byte i, j; for (j = 0; j < HEIGHT; j++) {
- for (i = 0; i < WIDTH; i++ ) {
- setPixel(i, j, no, 0);
- }
- }
- }
- #define RNUM_SEED 0xBAD
- static uint16_t rnum = RNUM_SEED;
- void paintCM5() {
- int i, j; bool pixel;
- for (i = 0; i < WIDTHR; i++ ) {
- for (j = 0; j < HEIGHTR; j++) {
- pixel = getPixel(i, j, 0);
- if (j & ROWCHANGE) {
- if (pixel == 1 ) {
- HardwarePlot(j, i, 0);
- }
- else {
- HardwarePlot(j, i, 1);
- }
- }
- else if (pixel == 1 ) {
- HardwarePlot(j, (WIDTHR - 1) - i, 0);
- }
- else {
- HardwarePlot(j, (WIDTHR - 1) - i, 1);
- }
- }
- }
- }
- static uint16_t get_random_bit(void)
- {
- #define X rnum
- uint16_t lfsr_bit = ((X >> 0) ^ (X >> 1) ^ (X >> 3) ^ (X >> 12)) & 1;
- uint16_t rand_bit = (X | (X >> 2)) & 1;
- #undef X
- rnum = (lfsr_bit << 15) | (rnum >> 1);
- return rand_bit;
- }
- void cm5() {
- int pixel, i, j;
- int count = 0;
- clearArray(0);
- //cm5 mode 7
- uint16_t gen_bit;
- uint16_t rnum = 1;
- while (count < 3080) {
- for (j = 63; j >= 0; j-- ) {
- uint16_t bit = get_random_bit();
- if (bit == 0) {
- setPixel(16, j, 0, 1);
- }
- }
- for (j = 0; j < 64; j++) {
- for (i = 0; i < 16 + 1; i++) {
- pixel = getPixel(i + 1, j, 0); if (pixel == 1) setPixel(i, j, 0, 1); else setPixel(i, j, 0, 0);
- }
- }
- count++;
- if (count > 0) {
- paintCM5();
- delay(MOVEDELAY); //131
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement