Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://xantorohara.github.io/led-matrix-editor/#ff00000000000000
- //http://robojax.com/learn/arduino/8x8LED/
- //We always have to include the library
- #include "LedControl.h"
- #include <TimerOne.h>
- /*
- Now we need a LedControl to work with.
- ***** These pin numbers will probably not work with your hardware *****
- pin 12 is connected to the DataIn
- pin 11 is connected to the CLK
- pin 10 is connected to LOAD
- We have only a single MAX72XX.
- */
- const byte interruptPinA = 2;
- const byte interruptPinB = 3;
- const byte interruptPinC = 18;
- const int led = LED_BUILTIN; // the pin with a LED
- int ledState = LOW;
- volatile unsigned long blinkCount = 0; // use volatile for shared variables
- volatile byte state = 0;
- LedControl lc = LedControl(12, 11, 10, 1);
- byte LEFT[] = { B00011000, B00110000, B01100000, B11011111, B11011111, B01100000, B00110000, B00011000};
- byte RIGHT[] = { B00011000, B00001100, B00000110, B11111011, B11111011, B00000110, B00001100, B00011000};
- byte UP[] = { B00011000, B00111100, B01100110, B11011011, B10011001, B00011000, B00011000, B00011000};
- byte DN[] = { B00011000, B00011000, B00011000, B10011001, B11011011, B01100110, B00111100, B00011000};
- byte DIAMOND[] = { B00011000, B00111100, B01111110, B11111111, B11111111, B01111110, B00111100, B00011000};
- byte SQUARE0[] = { B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111, B11111111};
- byte SQUARE1[] = { B00100100, B01000010, B10000001, B00000000, B00000000, B10000001, B01000010, B00100100};
- byte SQUARE2[] = { B00000000, B00100100, B01100110, B00000000, B00000000, B01100110, B00100100, B00000000};
- byte SQUARE3[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
- byte CIRCLE0[] = { B00000000, B00000000, B00000000, B00011000, B00011000, B00000000, B00000000, B00000000};
- byte CIRCLE1[] = { B00000000, B00000000, B00011000, B00100100, B00100100, B00011000, B00000000, B00000000};
- byte CIRCLE2[] = { B00000000, B00111100, B01000010, B01000010, B01000010, B01000010, B00111100, B00000000};
- byte CIRCLE3[] = { B01111110, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B01111110};
- byte BANK[8][8];
- byte VAR1[] = { B10000000,
- B10000000,
- B10000000,
- B10000000,
- B10000000,
- B10000000,
- B10000000,
- B10000000
- };
- byte TEST[] = { B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B11111111};
- byte TEMP[8] ;
- /* we always wait a bit between updates of the display */
- unsigned long delaytime = 50;
- void setup() {
- /*
- The MAX72XX is in power-saving mode on startup,
- we have to do a wakeup call
- */
- lc.shutdown(0, false);
- /* Set the brightness to a medium values */
- lc.setIntensity(0, 8);
- /* and clear the display */
- lc.clearDisplay(0);
- attachInterrupt(digitalPinToInterrupt(interruptPinA), MovetoLEFT, CHANGE);
- attachInterrupt(digitalPinToInterrupt(interruptPinB), MovetoRIGHT, CHANGE);
- attachInterrupt(digitalPinToInterrupt(interruptPinC), OFFMATRIX, CHANGE);
- //pinMode(interruptPinA,INPUT_PULLUP);
- //pinMode(interruptPinB,INPUT_PULLUP);
- //pinMode(interruptPinC,INPUT_PULLUP);
- Timer1.initialize(500000);
- Timer1.attachInterrupt(blinkLED); // blinkLED to run every 500ms
- pinMode(led, OUTPUT);
- }
- void blinkLED(void)
- {
- if (ledState == LOW) {
- ledState = HIGH;
- blinkCount = blinkCount + 1; // increase when LED turns on
- } else {
- ledState = LOW;
- }
- digitalWrite(led, ledState);
- }
- void matrix(byte PARAM[]) {
- for (int i = 0; i < 8; i++) {
- lc.setRow(0, i, PARAM[i]);
- }
- }
- void matrixShiftRIGHT(void) {
- //SHift to left
- memcpy(TEMP, RIGHT, 8); // or strcpy( TEMP, RIGHT);
- for (int j = 8; j > 0; j--) {
- for (int i = 0; i < 8; i++) {
- TEMP[i] = TEMP[i] << j;
- }
- matrix(TEMP);
- delay(delaytime);
- memcpy(TEMP, RIGHT, 8);
- }
- for (int j = 1; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- TEMP[i] = TEMP[i] >> j;
- }
- matrix(TEMP);
- delay(delaytime);
- memcpy(TEMP, RIGHT, 8);
- }
- }
- void matrixShiftLEFT(void) {
- //SHift to left
- memcpy(TEMP, LEFT, 8);
- for (int j = 8; j > 0; j--) {
- for (int i = 0; i < 8; i++) {
- TEMP[i] = TEMP[i] >> j;
- }
- matrix(TEMP);
- delay(delaytime);
- memcpy(TEMP, LEFT, 8);
- }
- for (int j = 0; j < 8; j++) {
- for (int i = 0; i < 8; i++) {
- TEMP[i] = TEMP[i] << j;
- }
- matrix(TEMP);
- delay(delaytime);
- memcpy(TEMP, LEFT, 8);
- }
- }
- void matrixShiftUP(void) {
- int k = 0;
- memcpy(TEMP, UP, 8);
- memcpy(BANK[k++], TEMP, 8);
- // matrix(TEMP);
- // delay(delaytime);
- for (int j = 0; j < 8; j++) {
- for (int i = 7; i > 0; i--) {
- TEMP[i] = TEMP[i - 1];
- }
- TEMP[0] = 0;
- // matrix(TEMP);
- memcpy(BANK[k++], TEMP, 8);
- // delay(delaytime);
- }
- for (int j = 7; j >= 0; j--) {
- matrix(BANK[j]);
- delay(delaytime);
- }
- memcpy(TEMP, UP, 8);
- for (int i = 0; i < 7; i++) {
- for (int i = 0; i < 7; i++) {
- TEMP[i] = TEMP[i + 1];
- }
- TEMP[7] = 0;
- matrix(TEMP);
- delay(delaytime);
- }
- }
- void matrixShiftDN(void) {
- memcpy(TEMP, DN, 8);
- matrix(TEMP);
- delay(delaytime);
- for (int i = 0; i <= 8; i++) {
- for (int i = 6; i >= 0; i--) {
- TEMP[i + 1] = TEMP[i];
- }
- TEMP[0] = 0;
- matrix(TEMP);
- delay(delaytime);
- }
- }
- void loop() {
- // switch (state) {
- // case 0:
- // break;
- // case 1:
- // break;
- // }
- if (state == 1) {
- matrixShiftRIGHT();
- } if (state == 2) {
- matrixShiftLEFT();
- }
- if (state == 3) {
- lc.clearDisplay(0);
- }
- // matrixShiftUP();
- // matrixShiftUP();
- // matrixShiftUP();
- // matrixShiftLEFT();
- // matrixShiftLEFT();
- // matrixShiftLEFT();
- // matrixShiftRIGHT();
- // matrixShiftRIGHT();
- // matrixShiftRIGHT();
- // matrix(LEFT);
- // delay(delaytime);
- // matrix(RIGHT);
- // delay(delaytime);
- // matrix(UP);
- // delay(delaytime);
- // matrix(DIAMOND);
- // delay(delaytime);
- // matrix(SQUARE);
- // delay(delaytime);
- // matrix(SQUARE1);
- // delay(delaytime);
- // matrix(SQUARE2);
- // delay(delaytime);
- // matrix(SQUARE3);
- // delay(delaytime);
- // matrix(CIRCLE0);
- // delay(delaytime);
- // matrix(CIRCLE1);
- // delay(delaytime);
- // matrix(CIRCLE2);
- // delay(delaytime);
- // matrix(CIRCLE3);
- // delay(delaytime);
- // for (int i = 0; i < 4; i++) {
- // matrix(CIRCLE3);
- // delay(delaytime);
- // matrix(CIRCLE2);
- // delay(delaytime);
- // matrix(CIRCLE1);
- // delay(delaytime);
- // }
- // lc.clearDisplay(0);
- // delay(100);
- }
- void MovetoLEFT() {
- state = 1;
- }
- void MovetoRIGHT() {
- state = 2;
- }
- void OFFMATRIX() {
- state = 3;
- }
Advertisement
Add Comment
Please, Sign In to add comment