Created
May 21, 2020 18:21
-
-
Save Robotto/facd6c7d952648fa8c7b6ad867859c7f to your computer and use it in GitHub Desktop.
Positive scroll text on large dot matrix display (max7219)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MAX7219 | |
#include <SPI.h> | |
#include <Adafruit_GFX.h> | |
#include <Max72xxPanel.h> | |
#define stringArraySize 7 | |
//int pinBatt = A0; | |
int pinCS = 8; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI ) | |
int numberOfHorizontalDisplays = 4; | |
int numberOfVerticalDisplays = 1; | |
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); | |
String results[stringArraySize] = { "Nice!", "Sweet!", "Lovely!", "Cute!", "Hot!", "Cool!", "Good!" }; | |
long randNumber; | |
long randoSeed; | |
int wait = 100; // In milliseconds | |
int spacer = 1; | |
int width = 5 + spacer; // The font width is 5 pixels | |
void setup() { | |
Serial.begin(9600); | |
matrix.setIntensity(7); // Use a value between 0 and 15 for brightness | |
// Adjust to your own needs | |
// matrix.setPosition(0, 0, 0); // The first display is at <0, 0> | |
// matrix.setPosition(1, 1, 0); // The second display is at <1, 0> | |
// matrix.setPosition(2, 2, 0); // The third display is at <2, 0> | |
// matrix.setPosition(3, 3, 0); // And the last display is at <3, 0> | |
// ... | |
matrix.setRotation(0, 1); // The first display is position upside down | |
matrix.setRotation(1, 1); // The first display is position upside down | |
matrix.setRotation(2, 1); // The first display is position upside down | |
matrix.setRotation(3, 1); // The same hold for the last display | |
matrix.fillScreen(LOW); | |
matrix.setCursor(2,1); | |
matrix.print("READY"); | |
matrix.write(); // Send bitmap to display | |
delay(1500); | |
matrix.fillScreen(LOW); | |
matrix.write(); // Send bitmap to display | |
/*while(true){ | |
matrix.fillScreen(LOW); | |
matrix.write(); // Send bitmap to display | |
matrix.setCursor(2,1); | |
matrix.print(analogRead(A1)*256); | |
matrix.write(); // Send bitmap to display | |
delay(100); | |
}*/ | |
for(int i=0;i<numberOfHorizontalDisplays*8-1;i++) { | |
matrix.drawPixel(i,3,true); | |
matrix.write(); // Send bitmap to display | |
randoSeed+=analogRead(A1); | |
delay(25); | |
} | |
for(int i=0;i<numberOfHorizontalDisplays*8-1;i++) { | |
matrix.drawPixel(i,3,false); | |
matrix.write(); // Send bitmap to display | |
randoSeed+=analogRead(A1); | |
delay(25); | |
} | |
delay(500); | |
randomSeed(randoSeed*512); | |
randNumber = random(stringArraySize); | |
Serial.print("Seed: "); Serial.println(randoSeed); | |
Serial.print("Generated Number: "); Serial.println(randNumber); | |
} | |
void loop() { | |
scrollText(results[randNumber]); | |
/* | |
matrix.fillScreen(LOW); | |
matrix.setCursor(2,1); | |
matrix.print("hello"); | |
matrix.write(); // Send bitmap to display | |
delay(500); | |
matrix.fillScreen(LOW); | |
matrix.setCursor(1,1); | |
matrix.print("WORLD"); | |
matrix.write(); // Send bitmap to display | |
delay(500); | |
counter++; | |
*/ | |
} | |
void scrollText(String str){ | |
for ( int i = 0 ; i < width * str.length() + matrix.width() - 1 - spacer; i++ ) { | |
matrix.fillScreen(LOW); | |
int letter = i / width; | |
int x = (matrix.width() - 1) - i % width; | |
int y = (matrix.height() - 8) / 2; // center the text vertically | |
while ( x + width - spacer >= 0 && letter >= 0 ) { | |
if ( letter < str.length() ) { | |
matrix.drawChar(x, y, str[letter], HIGH, LOW, 1); | |
} | |
letter--; | |
x -= width; | |
} | |
matrix.write(); // Send bitmap to display | |
delay(wait); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment