Go Down

Topic: HOW TO MOVE TEXT FROM LEFT TO RIGHT DIRECTION IN MAX7219 USING LED MATRIX 8*8 (Read 2779 times) previous topic - next topic

alhootti

HI GUYS
IM USING THE FOLLOW CODE IT IS WORKING  CORRECTLY , THE TEXT MOVE FROM RIGHT TO LEFT I NEED JUST MOVE THE TEXT FROM LEFT TO RIGHT ANY ONE CAN ASSIST ME.
Code: [Select]



#include <avr/pgmspace.h>
#include <LedControl.h>

const int numDevices = 1;      
const long scrollDelay = 250;  

unsigned long bufferLong [14] = {0};
LedControl lc=LedControl(12,11,10,numDevices);
prog_uchar scrollText[] PROGMEM ={
   "ALHOOTTI \0"};
void setup(){
   for (int x=0; x<numDevices; x++){
       lc.shutdown(x,false);      
       lc.setIntensity(x,15);      
       lc.clearDisplay(x);        
   }
}

void loop(){
   scrollMessage(scrollText);
   //scrollFont();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
prog_uchar font5x7 [] PROGMEM = {    
   B00000000, //Space (Char 0x20)
   B00000000,
   B00000000,
   B00000000,
   B00000000,
   B00000000,
   B00000000,
   6,

   B00011100, //A ?
   B00100010,
   B00100010,
   B00100010,
   B00011110,
   B00000100,
   B00001000,
   6,

   B00000100, //B ?
   B00000010,
   B00000010,
   B00000010,
   B01111110,
   B00101000,
   B00000000,
   6,

   B00100000, //C ?
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   6,

   B00011100, // D?
   B00100010,
   B00100010,
   B00010010,
   B00101010,
   B00100110,
   B01000000,

   6,

   B11111000, //E
   B10000000,
   B10000000,
   B11110000,
   B10000000,
   B10000000,
   B11111000,
   6,

   B11111000, //F
   B10000000,
   B10000000,
   B11110000,
   B10000000,
   B10000000,
   B10000000,
   6,

   B01110000, //G
   B10001000,
   B10000000,
   B10111000,
   B10001000,
   B10001000,
   B01111000,
   6,

   B10001000, //H
   B10001000,
   B10001000,
   B11111000,
   B10001000,
   B10001000,
   B10001000,
   6,

   B11100000, //I
   B01000000,
   B01000000,
   B01000000,
   B01000000,
   B01000000,
   B11100000,
   4,

   B00111000, //J
   B00010000,
   B00010000,
   B00010000,
   B00010000,
   B10010000,
   B01100000,
   6,

   B10001000, //K
   B10010000,
   B10100000,
   B11000000,
   B10100000,
   B10010000,
   B10001000,
   6,

   B10000000, //L
   B10000000,
   B10000000,
   B10000000,
   B10000000,
   B10000000,
   B11111000,
   6,

   B10001000, //M
   B11011000,
   B10101000,
   B10101000,
   B10001000,
   B10001000,
   B10001000,
   6,

   B10001000, //N
   B10001000,
   B11001000,
   B10101000,
   B10011000,
   B10001000,
   B10001000,
   6,

   B01110000, //O
   B10001000,
   B10001000,
   B10001000,
   B10001000,
   B10001000,
   B01110000,
   6,

   B11110000, //P
   B10001000,
   B10001000,
   B11110000,
   B10000000,
   B10000000,
   B10000000,
   6,

   B01110000, //Q
   B10001000,
   B10001000,
   B10001000,
   B10101000,
   B10010000,
   B01101000,
   6,

   B11110000, //R
   B10001000,
   B10001000,
   B11110000,
   B10100000,
   B10010000,
   B10001000,
   6,

   B01111000, //S
   B10000000,
   B10000000,
   B01110000,
   B00001000,
   B00001000,
   B11110000,
   6,

   B11111000, //T
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   6,

   B10001000, //U
   B10001000,
   B10001000,
   B10001000,
   B10001000,
   B10001000,
   B01110000,
   6,

   B10001000, //V
   B10001000,
   B10001000,
   B10001000,
   B10001000,
   B01010000,
   B00100000,
   6,

   B10001000, //W
   B10001000,
   B10001000,
   B10101000,
   B10101000,
   B10101000,
   B01010000,
   6,

   B10001000, //X
   B10001000,
   B01010000,
   B00100000,
   B01010000,
   B10001000,
   B10001000,
   6,

   B10001000, //Y
   B10001000,
   B10001000,
   B01010000,
   B00100000,
   B00100000,
   B00100000,
   6,

   B11111000, //Z
   B00001000,
   B00010000,
   B00100000,
   B01000000,
   B10000000,
   B11111000,
   6,

   B11100000, //[
   B10000000,
   B10000000,
   B10000000,
   B10000000,
   B10000000,
   B11100000,
   4,

   B00000000, //(Backward Slash)
   B10000000,
   B01000000,
   B00100000,
   B00010000,
   B00001000,
   B00000000,
   6,

   B11100000, //]
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   B00100000,
   B11100000,
   4,

   B00100000, //^
   B01010000,
   B10001000,
   B00000000,
   B00000000,
   B00000000,
   B00000000,
   6,

};

void scrollFont() {
   for (int counter=0x20;counter<0x80;counter++){
       loadBufferLong(counter);
       delay(500);
   }
}

// Scroll Message
void scrollMessage(prog_uchar * messageString) {
   int counter = 0;
   int myChar=0;
   do {
       // read back a char
       myChar =  pgm_read_byte_near(messageString + counter);
       if (myChar != 0){
           loadBufferLong(myChar);
       }
       counter++;
   }
   while (myChar != 0);
}
// Load character into scroll buffer
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*2];     // Load current scroll buffer
           x = x | c;                              // OR the new character onto end of current
           bufferLong [a*2] = x;                   // Store in buffer
       }
       byte count = pgm_read_byte_near(font5x7 +((ascii - 0x20) * 8) + 7);     // Index into character table for kerning data
       for (byte x=0; x<count;x++){
           rotateBufferLong();
           printBufferLong();
           delay(scrollDelay);
       }
   }
}
// Rotate the buffer
void rotateBufferLong(){
   for (int a=0;a<7;a++){                      // Loop 7 times for a 5x7 font
       unsigned long x = bufferLong [a*2];     // Get low buffer entry
       byte b = bitRead(x,31);                 // Copy high order bit that gets lost in rotation
       x = x<<1;                               // Rotate left one bit
       bufferLong [a*2] = x;                   // Store new low buffer
       x = bufferLong [a*2+1];                 // Get high buffer entry
       x = x<<1;                               // Rotate left one bit
       bitWrite(x,0,b);                        // Store saved bit
       bufferLong [a*2+1] = x;                 // Store new high buffer
   }
}  
// Display Buffer on LED matrix
void printBufferLong(){
 for (int a=0;a<7;a++){                    // Loop 7 times for a 5x7 font
   unsigned long x = bufferLong [a*2+1];   // Get high buffer entry
   byte y = x;                            
   lc.setRow(3,a,y);                      
   x = bufferLong [a*2];              
   y = (x>>8);                          
   lc.setRow(2,a,y);                    
   y = (x>>16);                          
   lc.setRow(1,a,y);                      
   y = (x>>24);                            
   lc.setRow(0,a,y);  
   // Send row to relevent MAX7219 chip
 }
}

Paul__B

Perhaps the first matter you need to resolve, is the problem you are having with your "Caps Lock" key.

C++ coding is case-sensitive and capitalising variables and functions will cause all sorts of compiling problems.

In Windoze, I have all my PCs set to "typewriter" mode where Caps Lock is cancelled by the Shift key - makes things much easier.  Unfortunately, many Linux versions are buggy on this function.

You could search these fora on the "Parola" project for information on scrolling.

alhootti


MAS3

He didn't tell you to use whatever you find instead of what you've got, if you look for 'parola'.
But you could find out how to determine scrolling direction by studying threads that are discussing this, and you might be able to put that in the sketch you've got now.
Scrolling texts have been discussed quite a lot over here, so you should be able to get this done.
All you need is the right words to search for, and 'parola' is it.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html


christianbenavent

Here a proposal. You must know the value of the array length, in the example below is the variable "Length".


Code: [Select]
void scrollText(char *p) {
for (int Length  = 18; Length  >= 0; Length --) {
     charWidth = mx.getChar(p[Length], sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
     for (uint8_t i=0; i<charWidth + 1; i++) {
       if (Length != 0 || i != charWidth) mx.transform(MD_MAX72XX::TSR);
       if (i < charWidth)
       mx.setColumn(95, cBuf[charWidth-i-1]);
       delay(DELAYTIME*2);
       }
 }
 }

Go Up