Go Down

Topic: 2 lines different lines of text on one sign (Read 416 times) previous topic - next topic

DJBud

Hey guys I need some help with some coding. I have a project where I am making a 2 line sign using 8 x 8 led matrix's, each line with its own text and controls. Making a single line sign Is relatively easy, add as many matrix's as you want in line. But I cannot find any reference online to controlling 2 different lines of text on one Arduino board. Is it possible?

Here is my code for a single line sign, thanks to Dejan Nedelkovski @ How To Mechatronics.com;

/*
     8x8 LED Matrix MAX7219 Scrolling Text
         Android Control via Bluetooth

  by Dejan Nedelkovski, www.HowToMechatronics.com

  Based on the following library:
  GitHub | riyas-org/max7219  https://github.com/riyas-org/max7219
*/

#include <MaxMatrix.h>
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>

PROGMEM const unsigned char CH[] = {
 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
 
};

int dIn = 7;   // DIN pin of MAX7219 module
int clk = 6;   // CLK pin of MAX7219 module
int cs = 5;    // CS pin of MAX7219 module

int maxInUse = 2;    // Number of MAX7219's connected

MaxMatrix m(dIn, cs, clk, maxInUse);
SoftwareSerial Bluetooth(8, 7); // Bluetooth

byte buffer[10];
char incomebyte;
int scrollSpeed = 100;
char text[100] = "HowToMechatronics.com  "; // Initial text message
int brightness = 15;
int count = 0;
char indicator;

void setup() {
 m.init(); // MAX7219 initialization
 m.setIntensity(brightness); // initial led matrix intensity, 0-15
 Bluetooth.begin(38400); // Default communication rate of the Bluetooth module
}

void loop() {
 // Printing the text
 printStringWithShift(text, scrollSpeed);
 
 if (Bluetooth.available()) {   // Checks whether data is comming from the serial port
   indicator = Bluetooth.read();   // Starts reading the serial port, the first byte from the incoming data
   // If we have pressed the "Send" button from the Android App, clear the previous text
   if (indicator == '1') {
     for (int i = 0; i < 100; i++) {
       text = 0;
       m.clear();
     }
     // Read the whole data/string comming from the phone and put it into text[] array.
     while (Bluetooth.available()) {
       incomebyte = Bluetooth.read();
       text[count] = incomebyte;
       count++;
     }
     count = 0;
   }
   // Adjusting the Scrolling Speed
   else if (indicator == '2') {
     String sS = Bluetooth.readString();
     scrollSpeed = 150 - sS.toInt(); // Milliseconds, subtraction because lower value means higher scrolling speed
   }
   // Adjusting the brightness
   else if (indicator == '3') {
     String sB = Bluetooth.readString();
     brightness = sB.toInt();
     m.setIntensity(brightness);
   }
 }

}

void printCharWithShift(char c, int shift_speed) {
 if (c < 32) return;
 c -= 32;
 memcpy_P(buffer, CH + 7 * c, 7);
 m.writeSprite(32, 0, buffer);
 m.setColumn(32 + buffer[0], 0);

 for (int i = 0; i < buffer[0] + 1; i++)
 {
   delay(shift_speed);
   m.shiftLeft(false, false);
 }
}

void printStringWithShift(char* s, int shift_speed) {
 while (*s != 0) {
   printCharWithShift(*s, shift_speed);
   s++;
 }
}

void printString(char* s)
{
 int col = 0;
 while (*s != 0)
 {
   if (*s < 32) continue;
   char c = *s - 32;
   memcpy_P(buffer, CH + 7 * c, 7);
   m.writeSprite(col, 0, buffer);
   m.setColumn(col + buffer[0], 0);
   col += buffer[0] + 1;
   s++;
 }
}

What do I do different?

Thanks for any help you could give me.

DJ Bud

PaulRB

Before we give you any help, please modify your post above and put in the code tags as requested in the forum guide. As you can see, the forum has corrupted your code because you did not use code tags.

DJBud

Sorry about that. I exceeded the number of lines for this message so I took out most of the letters from the array.

BTW Thanks for all of your help. It's people like you folks that help the rest of us!

Code: [Select]

#include <MaxMatrix.h>
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>

PROGMEM const unsigned char CH[] = {
  3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !

};

int dIn = 7;   // DIN pin of MAX7219 module
int clk = 6;   // CLK pin of MAX7219 module
int cs = 5;    // CS pin of MAX7219 module

int maxInUse = 4;    // Number of MAX7219's connected

MaxMatrix m(dIn, cs, clk, maxInUse);
SoftwareSerial Bluetooth(8, 7); // Bluetooth

byte buffer[10];
char incomebyte;
int scrollSpeed = 100;
char text[100] = "HowToMechatronics.com  "; // Initial text message
int brightness = 15;
int count = 0;
char indicator;

void setup() {
 m.init(); // MAX7219 initialization
  m.setIntensity(brightness); // initial led matrix intensity, 0-15
  Bluetooth.begin(9600); // Default communication rate of the Bluetooth module
}

void loop() {
  // Printing the text
  printStringWithShift(text, scrollSpeed);
 
  if (Bluetooth.available()) {   // Checks whether data is comming from the serial port
    indicator = Bluetooth.read();   // Starts reading the serial port, the first byte from the incoming data
    // If we have pressed the "Send" button from the Android App, clear the previous text
    if (indicator == '1') {
      for (int i = 0; i < 100; i++) {
        text[i] = 0;
        m.clear();
      }
      // Read the whole data/string comming from the phone and put it into text[] array.
      while (Bluetooth.available()) {
        incomebyte = Bluetooth.read();
        text[count] = incomebyte;
        count++;
      }
      count = 0;
    }
    // Adjusting the Scrolling Speed
    else if (indicator == '2') {
      String sS = Bluetooth.readString();
      scrollSpeed = 150 - sS.toInt(); // Milliseconds, subtraction because lower value means higher scrolling speed
    }
    // Adjusting the brightness
    else if (indicator == '3') {
      String sB = Bluetooth.readString();
      brightness = sB.toInt();
      m.setIntensity(brightness);
    }
  }

}

void printCharWithShift(char c, int shift_speed) {
  if (c < 32) return;
  c -= 32;
  memcpy_P(buffer, CH + 7 * c, 7);
  m.writeSprite(32, 0, buffer);
  m.setColumn(32 + buffer[0], 0);

  for (int i = 0; i < buffer[0] + 1; i++)
  {
    delay(shift_speed);
    m.shiftLeft(false, false);
  }
}

void printStringWithShift(char* s, int shift_speed) {
  while (*s != 0) {
    printCharWithShift(*s, shift_speed);
    s++;
  }
}

void printString(char* s)
{
  int col = 0;
  while (*s != 0)
  {
    if (*s < 32) continue;
    char c = *s - 32;
    memcpy_P(buffer, CH + 7 * c, 7);
    m.writeSprite(col, 0, buffer);
    m.setColumn(col + buffer[0], 0);
    col += buffer[0] + 1;
    s++;
  }
}

Delta_G

I don't know anything about this matrix library, but have you tried just defining a second object just like the first one and using it the same way?

Code: [Select]
MaxMatrix m(dIn, cs, clk, maxInUse);

Another line like this but with a different name and then use it just the same way.  Does that not work?

It would be my first guess. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

PerryBebbington

I don't know anything about the matrices either but would it work to construct them as 2 lines but wire them as 1 very long line, then print the stuff for the bottom line beginning half way along?

PaulRB

Quote
It's people like you folks that help the rest of us!
But it's hard to help people who don't listen.

DJBud

Hey guys, thanks help.

Delta_g, I'll try your suggestion for a second object.

Thanks

Go Up