Go Down

Topic: Textfield for scrolling Text on Matrix (Read 212 times) previous topic - next topic

sympaticz

Hello guys,

I need to do a project for school and I want to do a 8x16 matrix.
I have built two 8x8 matrix. Each is controlled by two 74HC595 Shiftregister. One for the rows and one for the columns.

It works fine, but it costs a lot of time to change the text. I have to copy the binary code of each letter of the text in an array.

Now I want to optimize the programm that I just need to write the text in a string or something like that.



Code: [Select]

// A 0b11111000,0b11111100,0b00100110,0b00100110,0b11111100,0b11111000,0b00000000,0b00000000,
// B 0b10000010,0b11111110,0b11111110,0b10010010,0b10010010,0b11111110,0b01101100,0b00000000,0b00000000,
// C 0b01111100,0b11111110,0b10000010,0b10000010,0b11000110,0b01000100,0b00000000,0b00000000,
// D 0b10000010,0b11111110,0b11111110,0b10000010,0b11000110,0b01111100,0b00111000,0b00000000,0b00000000,
// E 0b10000010,0b11111110,0b11111110,0b10010010,0b10111010,0b10000010,0b11000110,0b00000000,0b00000000,
// F 0b10000010,0b11111110,0b11111110,0b10010010,0b00111010,0b00000010,0b00000110,0b00000000,0b00000000,
// G 0b00111000,0b01111100,0b11000110,0b10000010,0b10100010,0b11100110,0b11100100,0b00000000,0b00000000,
// H 0b11111110,0b11111110,0b00010000,0b00010000,0b11111110,0b11111110,0b00000000,0b00000000,
// I 0b10000010,0b11111110,0b11111110,0b10000010,0b00000000,0b00000000,
// J 0b01100000,0b11100000,0b10000000,0b10000010,0b11111110,0b01111110,0b00000010,0b00000000,0b00000000,
// K 0b10000010,0b11111110,0b11111110,0b00010000,0b00111000,0b11101110,0b11000110,0b00000000,0b00000000,
// L 0b10000010,0b11111110,0b11111110,0b10000010,0b10000000,0b11000000,0b11100000,0b00000000,0b00000000,
// M 0b11111110,0b11111110,0b00001100,0b00011000,0b00001100,0b11111110,0b11111110,0b00000000,0b00000000,
// N 0b11111110,0b11111110,0b00001100,0b00011000,0b00110000,0b11111110,0b11111110,0b00000000,0b00000000,
// O 0b00111000,0b01111100,0b11000110,0b10000010,0b11000110,0b01111100,0b00111000,0b00000000,0b00000000,
// P 0b10000010,0b11111110,0b11111110,0b10010010,0b00010010,0b00011110,0b00001100,0b00000000,0b00000000,
// Q 0b00111100,0b01111110,0b01000010,0b11100010,0b11111110,0b10111100,0b00000000,0b00000000,
// R 0b10000010,0b11111110,0b11111110,0b00010010,0b00110010,0b11111110,0b11001100,0b00000000,0b00000000,
// S 0b01001100,0b11011110,0b10011010,0b10110010,0b11100110,0b01100100,0b00000000,0b00000000,
// T 0b00000110,0b10000010,0b11111110,0b11111110,0b10000010,0b00000110,0b00000000,0b00000000,
// U 0b11111110,0b11111110,0b10000000,0b10000000,0b11111110,0b11111110,0b00000000,0b00000000,
// V 0b00111110,0b01111110,0b11000000,0b11000000,0b01111110,0b00111110,0b00000000,0b00000000,
// W 0b11111110,0b11111110,0b01100000,0b00110000,0b01100000,0b11111110,0b11111110,0b00000000,0b00000000,
// X 0b10000110,0b11001110,0b01111000,0b00110000,0b01111000,0b11001110,0b10000110,0b00000000,0b00000000,
// Y 0b00001110,0b10011110,0b11110000,0b11110000,0b10011110,0b00001110,0b00000000,0b00000000,
// Z 0b10001110,0b11000110,0b11100010,0b10110010,0b10011010,0b11001110,0b11100110,0b00000000,0b00000000,
// SPACE_GROß 0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,
// SPACE_KLEIN 0b00000000,0b00000000,0b00000000,0b00000000,
//, 0b10000000,0b01000000,0b00000000,0b00000000,
//. 0b11000000,0b11000000,0b00000000,0b00000000
//? 0b00001100,0b00000010,0b10110010,0b00010010,0b00001100,0b00000000,0b00000000,
//! 0b10111110,0b00000000,0b00000000,
//- 0b00010000,0b00010000,0b00010000,0b00000000,0b00000000,





const int latchPin = A8;    //Pin connected to ST_CP of 74HC595
const int clockPin = A12;   //Pin connected to SH_CP of 74HC595
const int dataPin = A11;    //Pin connected to DS of 74HC595

const int latchPin2 = A2;  //Pin connected to ST_CP of 74HC595
const int clockPin2 = A3;  //Pin connected to SH_CP of 74HC595
const int dataPin2 = A0;   //Pin connected to DS of 74HC595


int data[] = {                                                                                     
  0b11111110,0b11111110,0b00010000,0b00010000,0b11111110,0b11111110,0b00000000,0b00000000,            //H
  0b10000010,0b11111110,0b11111110,0b10010010,0b10111010,0b10000010,0b11000110,0b00000000,0b00000000, //E
  0b10000010,0b11111110,0b11111110,0b10000010,0b10000000,0b11000000,0b11100000,0b00000000,0b00000000, //L
  0b10000010,0b11111110,0b11111110,0b10000010,0b10000000,0b11000000,0b11100000,0b00000000,0b00000000, //L
  0b00111000,0b01111100,0b11000110,0b10000010,0b11000110,0b01111100,0b00111000,0b00000000,0b00000000, //O
  };


void setup ()
{
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT);

  pinMode(latchPin2,OUTPUT);
  pinMode(clockPin2,OUTPUT);
  pinMode(dataPin2,OUTPUT);

  digitalWrite(latchPin, LOW);
  digitalWrite(clockPin, LOW);
  digitalWrite(dataPin, LOW);
  digitalWrite(latchPin2, LOW);
  digitalWrite(clockPin2, LOW);
  digitalWrite(dataPin2, LOW);
};


void loop()
{

  for(int n=0; n<44; n++)
  {
    for(int t=0; t<7; t++)
    {
      int dat = 1;
     
      for(int num = n; num < 8+n ; num++)
      {
        shiftOut(dataPin,clockPin,MSBFIRST, data[num]);
        shiftOut(dataPin2,clockPin2, MSBFIRST, data[num-8]);
        shiftOut(dataPin,clockPin,MSBFIRST,~dat);
        shiftOut(dataPin2,clockPin2,MSBFIRST,~dat);
        digitalWrite(latchPin,HIGH);
        digitalWrite(latchPin2,HIGH);
        digitalWrite(latchPin,LOW);
        digitalWrite(latchPin2,LOW);
        dat = dat<< 1; 
        delay(1);
      }
    }
  }
}




I guess it´s not the best solution for the matrix with four shiftregister and this code.
I just need held for that textfield. So you can just write the text in a field and the programm will automaticly take the right bytes for the data[].

I´m thankfull for any help!

PaulRB

Code: [Select]
int data[] = {                                                                                     
  0b11111110,0b11111110,0b00010000,0b00010000,0b11111110,0b11111110,0b00000000,0b00000000,            //H
  0b10000010,0b11111110,0b11111110,0b10010010,0b10111010,0b10000010,0b11000110,0b00000000,0b00000000, //E
  0b10000010,0b11111110,0b11111110,0b10000010,0b10000000,0b11000000,0b11100000,0b00000000,0b00000000, //L
  0b10000010,0b11111110,0b11111110,0b10000010,0b10000000,0b11000000,0b11100000,0b00000000,0b00000000, //L
  0b00111000,0b01111100,0b11000110,0b10000010,0b11000110,0b01111100,0b00111000,0b00000000,0b00000000, //O
  };

Why is there a byte of data missing?

sympaticz

Because I only need 8 columns for a good looking "H". The least two columns are only 0, so the letters all have the same diatance to each other. Is this a problem and should I change it?

PaulRB

So where is the data that tells the sketch that some letters require more bytes than other letters? If a zero byte indicates the end of the data for a letter, where is the code that checks for that zero byte?

sympaticz

One Byte is one column. When there are for example 0B00000000 then all LED's in this column are off. This column get "pushed" from the right to the left over the matrix.
When I have:
0B00000000
0B11111111
0B00000000
0B11111111

Then I have one column of LED's which is on and the next column is off. The third one is on an the next one is off. You know what I mean?


I need a string where i can write the text in and then a pointer to arrays for the letters.
So when I want to write "Hi" the code automaticly takes the binary code of the "H" and after that the binary code of the "i". And this row of binary codes should be shown on the matrix.

PaulRB

Right, I get it. Because you are compiling the binary patterns yourself, you know how many columns each letter requires, or you keep copying binary patterns until you see a zero byte?

Well the good news is... from what I have seen of your coding abilities so far, this is within or only just a few small steps beyond your current level of ability. So a good opportunity to practice and learn a little more.

Start like this. Think about how you currently perform the process by hand, step by step. Then maybe think about how you would explain to a friend how to do it.

Clearly, you need to repeat a process for each letter in your message in turn. For each letter, you have to go find the start of the binary patterns for that letter. Then you copy the patterns into a "buffer" until all the bytes for that letter have been copied. As each byte is copied to the buffer, you need to move on to the next position in the buffer. Once all letters have been done, your existing code will send that to the display.

Go Up