Hey all! This code scrolls text specified in the variables byte numPatterns and byte patterns on an 8x10 LED matrix. The way this code is written requires you to assign the value of byte numPatters to the number of characters and spaces in the text, and requires you to type out each character of the text in byte patterns.
How can this code be adapted so that text typed in the serial monitor can be displayed on the LED Matrix?
One way I was thinking was:
- Use Serial.Read to count the number characters (in order to update byte numPatterns).
- Somehow use Serial.Read to separate each character and place each as separate elements of byte patterns.
How should this be accomplished? How could Serial.Read recognize a space typed, in order to display a space between letters on the Matrix?
All comments and input is appreciated!
-Skyler
Here is the instructables I used the code from
http://www.instructables.com/id/810-LED-Matrix-with-4017/ Instructables for LED Matrix
int DataPin = 9;
int LatchPin = 11;
int ClockPin = 10;
int clock = 13;
int Reset = 12;
//x,y for the loop
int x;
int y;
const int numPatterns = 17;//this is the number of patterns you want to display
byte patterns[numPatterns][10] = {space, M, A, D, E, space, B, Y, space, V, A, D, I, M, space}; // the patterns order
// here the definion of all the letter(big ans small) and numbers
#define A {B00000000,B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B00000000}
#define B {B00000000,B01111100,B01000010,B01000010,B01111100,B01000010,B01000010,B01000010,B01111100,B00000000}
#define C {B00000000,B00111110,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B00111110,B00000000}
#define D {B00000000,B01111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01111100,B00000000}
#define E {B00000000,B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01111110,B00000000}
#define F {B00000000,B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01000000,B00000000}
#define G {B00000000,B00111100,B01000010,B01000010,B01000000,B01000111,B01000010,B01000010,B00111100,B00000000}
#define H {B00000000,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B01000010,B00000000}
#define I {B00000000,B00111000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00111000,B00000000}
#define J {B00000000,B00011100,B00001000,B00001000,B00001000,B00001000,B01001000,B01001000,B00110000,B00000000}
#define K {B00000000,B01000100,B01001000,B01010000,B01100000,B01010000,B01001000,B01000100,B01000010,B00000000}
#define L {B00000000,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B01111110,B00000000}
#define M {B00000000,B01000100,B10101010,B10010010,B10010010,B10000010,B10000010,B10000010,B10000010,B00000000}
#define N {B00000000,B01000010,B01100010,B01010010,B01001010,B01001010,B01001010,B01000110,B01000010,B00000000}
#define O {B00000000,B00111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00111100,B00000000}
#define P {B00000000,B00111100,B01000010,B01000010,B01000010,B01111100,B01000000,B01000000,B01000000,B00000000}
#define Q {B00000000,B00111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000110,B00111110,B00000001}
#define R {B00000000,B00111100,B01000010,B01000010,B01000010,B01111100,B01000100,B01000010,B01000010,B00000000}
#define S {B00000000,B00111100,B01000010,B01000000,B01000000,B00111100,B00000010,B01000010,B00111100,B00000000}
#define T {B00000000,B11111110,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00000000}
#define U {B00000000,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00111100,B00000000}
#define V {B00000000,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000,B00000000}
#define W {B00000000,B10000010,B10000010,B10000010,B10000010,B10010010,B10010010,B10101010,B01000100,B00000000}
#define X {B00000000,B01000010,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B01000010,B00000000}
#define Y {B00000000,B10000010,B01000100,B00101000,B00010000,B00010000,B00010000,B00010000,B00010000,B00000000}
#define Z {B00000000,B01111110,B00000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110,B00000000}
#define space {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}
#define num_0 {B00000000,B00111100,B01000110,B01001010,B01001010,B01001010,B01010010,B01100010,B00111100,B00000000}
#define num_1 {B00000000,B00001000,B00011000,B00001000,B00001000,B00001000,B00001000,B00001000,B00011100,B00000000}
#define num_2 {B00000000,B00111100,B01000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110,B00000000}
#define num_3 {B00000000,B01111110,B00000010,B00000010,B00011100,B00000010,B00000010,B01000010,B00111100,B00000000}
#define num_4 {B00000000,B00000100,B00001100,B00010100,B00100100,B01000100,B01111110,B00000100,B00000100,B00000000}
#define num_5 {B00000000,B01111110,B01000000,B01000000,B00111100,B00000010,B00000010,B00000010,B01111100,B00000000}
#define num_6 {B00000000,B00111100,B01000000,B01000000,B01111100,B01000010,B01000010,B01000010,B00111100,B00000000}
#define num_7 {B00000000,B01111110,B00000010,B00000100,B00001000,B00010000,B00010000,B00010000,B00010000,B00000000}
#define num_8 {B00000000,B00111100,B01000010,B01000010,B00111100,B01000010,B01000010,B01000010,B00111100,B00000000}
#define num_9 {B00000000,B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00111100,B00000000}
#define times {B00000000,B00000000,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B00000000,B00000000}
void setup() {
pinMode(DataPin, OUTPUT);
pinMode(ClockPin, OUTPUT);
pinMode(LatchPin, OUTPUT);
//simple stuff here
pinMode(clock, OUTPUT);
pinMode(Reset, OUTPUT);
//reseting the 4017 IC, you have to do this
digitalWrite(Reset, HIGH);
delayMicroseconds(5);
digitalWrite(Reset, LOW);
}
void display_pattern(int loops)//int loop acts like a delay, it take 8 mSecands to scan all of the rows so int loops = 15 is a good time for it
{
for (x = 0; x < numPatterns - 1; x++) { // loop over the patterns
for (int z = 0; z < 8; z++) { //scrolls one bit at a time
for (int t = 0; t < loops; t++) { // the delay we get with loops
for (y = 0; y < 10; y++) { // loops over the array of bytes
byte temp = patterns[x][y];
byte temp_2 = patterns[x + 1][y];
digitalWrite(LatchPin, 0);
shiftOut(DataPin, ClockPin, MSBFIRST, ((temp << z) + (temp_2 >> 7 - z))); //writes digital outputs, Z is for how much bits it need to scroll
digitalWrite(LatchPin, 1); //data is only showed on the output after latch toggles from 0 to 1
delayMicroseconds(800);
digitalWrite(LatchPin, 0);
shiftOut(DataPin, ClockPin, MSBFIRST, 0);
digitalWrite(LatchPin, 1);
digitalWrite(clock, HIGH);
digitalWrite(clock, LOW);
}
}
}
}
}
void loop() {
display_pattern(15);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrrol slower).
}