Go Down

Topic: Sketch examples of scrolling text on 8x8 LED matrix w/ MAX72xx (Read 15 times) previous topic - next topic

Riva


Thanks Riva, I will give it a try tonight!  I soldered 2 matricies with MAX7219 chips and will see it runs on it.
I'm still trying to come up with my own code, but due to lack of programming knowledge, it's hard but fun :)

I have a couple of clocks using 16x8 LED matrix controlled by a pair of MAX7219 chips but one is 400 miles away and the other is not to be messed with #so says the wife :) I'm sure you will get the hang of it. I've only been programming C++ since February 2012 though I have used other languages for about 30 years.

bratan

#21
Oct 18, 2012, 10:16 pm Last Edit: Oct 19, 2012, 02:05 am by bratan Reason: 1
30 years!  :smiley-eek:
Trying to understand your code, I think I'm starting to get it. Right off the bet, I found tiny issue: need to initialize second display (lc.shutdown(1,false);  etc).
Also why bufferLong is 7?  Should it be 14 if using 2 displays?  Or it doesn't matter?
What does this this code exactly performs?
Code: [Select]
pgm_read_byte_near(font5x7 + ((ascii - 0x20) * 8) + a);
I understand you are reading it from prog memory and offsetting by 20 characters to get right ASCII, but not sure what "*8" is for and what "font5x7 +" does? Your adding something to an array name not array's element?   :~
Sorry for stupid questions :)

Edit: Ok I hooked up my LED matrices, and your code totally works... except it looks like I have mine wired/arranged differently from yours :(   Instead of scrolling from one matrix to another, it scrolls as if they arranged one on top of each other (i.e. image is rotated 90 degrees clockwise, so it's not going from right to left, but from bottom to the top on each). I need to figure how to to rotate image 90 degrees CW (i.e. rows become columns, etc.).
Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, and purchasing info :)

Pedro147

Riva,

I just tried your ScrollTest 4 MAX code on my Max 7219, 8 x 8 Matrix set up and I can report that it works perfectly. I am not 100% sure, but when I compared it with your ScrollTest 2 version I think that there are two column spaces between chars with the ScrollTest 2 version but only one column space with the ScrollTest 4 version but I may be mistaken as it scrolls quite quickly and I couldn't find the code section that would slow down the scroll speed to verify this. I linked a short video of the 4 version so you can see what you think or if you tell me how to adjust the scroll speed code I will verify my suspicions. Once again excellent nice clean fonts,

Pedro.

p.s. I hope you did not mind me posting this on my youtube channel so I could show you, and if you wish me to remove it just ask and I'll take it off.
http://www.youtube.com/watch?v=cY8xOCN1KR0&feature=bf_prev&list=ULzDMQ-c1nh6c

Riva


Also why bufferLong is 7?  Should it be 14 if using 2 displays?  Or it doesn't matter?

I am using a 5x7 font (5 bits wide x 7 bits deep) but it is stored as 8 bits wide (byte) as this is what processors like and it makes the maths easy  XD. The font is only 7 bits tall so I only need 7 buffers but these buffers are longs so are 32 bits wide. What happens when you scroll a character is it's matrix data (8 bits wide) is loaded from font5x7 and places in the lower 8 bits of the 7 bufferLong's (keeping the upper 24 bits) it then reads the 8th byte from the font5x7 matrix data that is the number of bits to scroll this particular character (kerning). It rotates the bufferLong's by 1 bit and then displays the bits 16-23 in the first (left) LED matrix and bits 8-15 in the right LED matrix. It keeps rotating one bit at a time and displaying until the character width has rotated out of the lower 8 bits of the buffer and then goes back to get the next character so scroll.

Quote
What does this this code exactly performs?
Code: [Select]
pgm_read_byte_near(font5x7 + ((ascii - 0x20) * 8) + a);
I understand you are reading it from prog memory and offsetting by 20 characters to get right ASCII, but not sure what "*8" is for and what "font5x7 +" does? Your adding something to an array name not array's element? 

The font data is stored as a single dimension byte array (a contiguous block of memory), I need 7 bytes to describe the font data for a single character and the 8th byte is the width of that character in bits (used for kerning). font5x7 point to the starts of this memory so for each increment in the Ascii number I have to jump 8 bytes of this contiguous memory to find the start of that characters font data.
Quote

Edit: Ok I hooked up my LED matrices, and your code totally works... except it looks like I have mine wired/arranged differently from yours :(   Instead of scrolling from one matrix to another, it scrolls as if they arranged one on top of each other (i.e. image is rotated 90 degrees clockwise, so it's not going from right to left, but from bottom to the top on each). I need to figure how to to rotate image 90 degrees CW (i.e. rows become columns, etc.).

To do this you would need to re-define the font data and alter the way scrolling works, I'm sure someone else has done scrolling this way so if you find the fonts and code it could be adapted to the MAX7219.

Riva


I just tried your ScrollTest 4 MAX code on my Max 7219, 8 x 8 Matrix set up and I can report that it works perfectly. I am not 100% sure, but when I compared it with your ScrollTest 2 version I think that there are two column spaces between chars with the ScrollTest 2 version but only one column space with the ScrollTest 4 version but I may be mistaken as it scrolls quite quickly and I couldn't find the code section that would slow down the scroll speed to verify this. I linked a short video of the 4 version so you can see what you think or if you tell me how to adjust the scroll speed code I will verify my suspicions. Once again excellent nice clean fonts,

Adjust this to alter the scroll speed.
Code: [Select]
const long scrollDelay = 70;

This version is a slight improvement (in my opinion) on ScrollTest2 as it does character kerning. It only scrolls the width of the character instead of a fixed width of the old version. This makes the display look neater when text has mix of wide and narrow characters like M & I respectfully.
A quick an easy hack to alter the overall spacing between characters is to add the below highlighted line
Quote
void loadBufferLong(int ascii){
    if (ascii >= 0x20 && ascii <=0x7f){
        for (int a=0;a<7;a++){                      // Loop 7 times for a 5x7 font
            unsigned long c = pgm_read_byte_near(font5x7 + ((ascii - 0x20) * 8) + a);     // Index into character table to get row data
            unsigned long x = bufferLong [a];       // Load current scroll buffer
            x = x | c;                              // OR the new character onto end of current
            bufferLong [a] = x;                     // Store in buffer
        }
        byte count = pgm_read_byte_near(font5x7 +((ascii - 0x20) * 8) + 7);     // Index into character table for kerning data
        count++
        for (byte x=0; x<count;x++){
            rotateBufferLong();
            printBufferLong();
            delay(scrollDelay);
        }
    }
}


Go Up