c++ Array Help

Discussion in 'Programmer's Corner' started by kurtruk, Feb 12, 2014.

  1. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    I am working on a project that takes a line of characters typed on a computer and displays them on a 50x8 LED Matrix controlled by an arduino. I am having trouble with the scrolling part.

    This is how I would like to do it:
    Have two bitmaps a msgbitmap and a bitmap. The msgbitmap is sent to the arduino via serial (I know how to make the msgbitmap, but have not written the code for the serial communications yet). The bitmap would be what is actually displayed on the Matrix at any "point" in time. I am not sure how to shift the msgbitmap gradually into the bitmap.

    I know it has to go like this:
    1st shift:
    bitmap[0][49] = msgbitmap [0][0]
    bitmap[1][49] = msgbitmap [1][0]
    bitmap[2][49] = msgbitmap [2][0]
    bitmap[3][49] = msgbitmap [3][0]
    bitmap[4][49] = msgbitmap [4][0]
    bitmap[5][49] = msgbitmap [5][0]
    bitmap[6][49] = msgbitmap [6][0]
    bitmap[7][49] = msgbitmap [7][0]

    //set rest to 0?

    2nd Shift:
    bitmap[0][49] = msgbitmap [0][1]
    bitmap[1][49] = msgbitmap [1][1]
    bitmap[2][49] = msgbitmap [2][1]
    bitmap[3][49] = msgbitmap [3][1]
    bitmap[4][49] = msgbitmap [4][1]
    bitmap[5][49] = msgbitmap [5][1]
    bitmap[6][49] = msgbitmap [6][1]
    bitmap[7][49] = msgbitmap [7][1]

    bitmap[0][48] = msgbitmap [0][0]
    bitmap[1][48] = msgbitmap [1][0]
    bitmap[2][48] = msgbitmap [2][0]
    bitmap[3][48] = msgbitmap [3][0]
    bitmap[4][48] = msgbitmap [4][0]
    bitmap[5][48] = msgbitmap [5][0]
    bitmap[6][48] = msgbitmap [6][0]
    bitmap[7][48] = msgbitmap [7][0]

    //set rest to 0?

    3rd shift:

    bitmap[0][49] = msgbitmap [0][2]
    bitmap[1][49] = msgbitmap [1][2]
    bitmap[2][49] = msgbitmap [2][2]
    bitmap[3][49] = msgbitmap [3][2]
    bitmap[4][49] = msgbitmap [4][2]
    bitmap[5][49] = msgbitmap [5][2]
    bitmap[6][49] = msgbitmap [6][2]
    bitmap[7][49] = msgbitmap [7][2]

    bitmap[0][48] = msgbitmap [0][1]
    bitmap[1][48] = msgbitmap [1][1]
    bitmap[2][48] = msgbitmap [2][1]
    bitmap[3][48] = msgbitmap [3][1]
    bitmap[4][48] = msgbitmap [4][1]
    bitmap[5][48] = msgbitmap [5][1]
    bitmap[6][48] = msgbitmap [6][1]
    bitmap[7][48] = msgbitmap [7][1]

    bitmap[0][47] = msgbitmap [0][0]
    bitmap[1][47] = msgbitmap [1][0]
    bitmap[2][47] = msgbitmap [2][0]
    bitmap[3][47] = msgbitmap [3][0]
    bitmap[4][47] = msgbitmap [4][0]
    bitmap[5][47] = msgbitmap [5][0]
    bitmap[6][47] = msgbitmap [6][0]
    bitmap[7][47] = msgbitmap [7][0]

    //set rest to 0?
    ............
    I know this can be done in a forloop, but I just can't seem to figure it out.
     
  2. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    This is code that I think would work, but for some reason doesn't. Note their are two msgbitmap for two colors (red and green).

    Code ( (Unknown Language)):
    1. void shift(){
    2. bool rmsgbitmap[8][50] = {
    3.                     {0,1,0,0,0,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0},
    4.                     {0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0},
    5.                     {0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0},
    6.                     {0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0},
    7.                     {0,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0},
    8.                     {0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
    9.                     {0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
    10.                     {0,1,0,0,0,1,0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0}
    11.                    };
    12.  
    13.  
    14. bool  gmsgbitmap[8][50] = {
    15.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0},
    16.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
    17.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
    18.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
    19.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0},
    20.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0},
    21.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0},
    22.                     {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0}};
    23. int runTimes = timesShifted;
    24. for(int row=0; row<8; row++){
    25.     for(int col=49; col>-1; col--){
    26.         for(int i=-1; i < timesShifted; i++){  //heres where it would break down if the msg is greater than 50 columns
    27.             rbitmap[row][col] = rmsgbitmap[row][runTimes];
    28.             gbitmap[row][col] = gmsgbitmap[row][runTimes];
    29.             runTimes--;
    30.         }
    31.     }
    32. }
    33. timesShifted++;
    34.  
    35.  
    36.  
    37. };
    This seems like it would work as long as the msg is less than 50 columns but it does not work.

    P.S. sorry for my badly named ints.
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,379
    494
    row and col don't seem to be defined.
     
  4. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    They are defined inside of the for loop parameters, right?
     
  5. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    After more thinking I think the above code won't work.

    I just need a simple way to shift one array into another.
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Cart, horse, even since that damn automobile got invented no on knows which one goes first!

    DO work out what needs to get done, THEN figure out how to do it.

    Is there a plan to display a bitmap? Is it written down somewhere?

    Next, is there a plan to shift a bitmap? Is it written down somewhere?

    You can't (well, should not) start until you have both.

    Until you have both no one else can help you. That is absolute.
     
  7. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    Sir, If you had read my first post you would know their is a plan
    The display is done.

    I know what needs to be done. I just didn't know how to do it. That's why I asked for help.


    I have ended up adding ten spaces to begin the msgbitmap so it is easier to do the shifting. (so that I can start at the beginning and not have it dynamically grow). This will work, but I am still wondering if it is possible to do it the other way.

    And in addition with that way I won't even need a separate shift function I can just integrate into the function that actually tells the matrix what to display
     
    Last edited: Feb 13, 2014
  8. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    So I got it work partially. It displays the green perfectly except for three pixels that are always on for some reason. I have tested the hardware nothing is wrong.

    The red is another story it display random garbage.

    I have tried numerous different ways. checked my code again and again and can't figure out why it is not working.

    Here is the main.cpp:

    Code ( (Unknown Language)):
    1. /*50 X 8 Scrolling Matrix
    2.  Author: Kurt
    3. Date 2/14/14
    4. Version 2.0 */
    5.  
    6. #include "DisplayClass.h"
    7.  
    8. void setup(){
    9.   DisplayClass o;
    10.   o.Setup();
    11.   /*for(int r=0;r<8;r++){
    12.     for(int c=0;c<50;c++){
    13.       o.rbitmap[r][c] = 0;
    14.     }
    15.   }
    16.   for(int r=0;r<8;r++){
    17.     for(int c=0;c<50;c++){
    18.       o.gbitmap[r][c] = 0;
    19.     }
    20.   }*/
    21. }
    22.  
    23. void loop (){
    24.   DisplayClass o;
    25.   o.Setup();
    26.   while(1){
    27.     for(int Speed=0;Speed<10;Speed++){
    28.     o.refresh();
    29.     }
    30.     o.shift();
    31.   }
    32. }
    DisplayClass.h:
    Code ( (Unknown Language)):
    1. #ifndef DISPLAYCLASS_H
    2. #define DISPLAYCLASS_H
    3.  
    4.  
    5. class DisplayClass
    6. {
    7.     public:
    8.       int row1; //binary value for row select
    9.       int row2; //binary value for row select
    10.       int row3; //binary value for row select
    11.       int rowE; // row enable enable display LOW ON
    12.       int rclk; // register clk latch
    13.       int clk; // serial clock input
    14.       int rdat; // red serial data
    15.       int gdat; // green serial date
    16.      
    17.       int Shift;
    18.      
    19.       bool  rbitmap [8][50];
    20.       bool  gbitmap [8][50];
    21.      
    22.       void refresh();
    23.       void Setup();
    24.       void shift();
    25. };
    26.  
    27. #endif // DISPLAYCLASS_H
    DisplayClass.cpp
    Code ( (Unknown Language)):
    1. #include "DisplayClass.h"
    2. #include "Arduino.h"
    3.  
    4. bool gmsgbitmap [8][126] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    5.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    6.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    7.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    8.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    9.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    10.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    11.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    12.                      
    13. bool rmsgbitmap [8][126] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    14.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    15.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    16.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    17.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    18.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    19.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    20.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    21.  
    22.  
    23. void DisplayClass::refresh(){  
    24.   for (int row=0; row<8; row++){
    25.     digitalWrite (rowE, HIGH);
    26.     digitalWrite (rclk, LOW);
    27.  
    28.     for (int col=0; col < 50; col++){
    29.       digitalWrite(gdat, LOW);
    30.       digitalWrite(rdat, LOW);
    31.      
    32.        if ((gbitmap [row][col]) == 1) {
    33.          digitalWrite(gdat, HIGH);
    34.        }
    35.        else digitalWrite (gdat, LOW);
    36.        
    37.        if ((rbitmap [row][col]) == 1){
    38.          digitalWrite(rdat, HIGH);
    39.        }
    40.        else digitalWrite (rdat, LOW);
    41.      
    42.       digitalWrite(clk, HIGH);
    43.       digitalWrite(clk, LOW);
    44.     }
    45.  
    46.     digitalWrite(rclk, HIGH);
    47.     if bitRead(row,0) digitalWrite (row1, HIGH); else digitalWrite(row1, LOW);
    48.     if bitRead(row,1) digitalWrite (row2, HIGH); else digitalWrite(row2, LOW);
    49.     if bitRead(row,2) digitalWrite (row3, HIGH); else digitalWrite(row3, LOW);
    50.     digitalWrite(rowE, LOW);
    51.     delayMicroseconds(600);    
    52.   }
    53. }
    54.  
    55.  
    56. void DisplayClass::Setup(){
    57.   row1 = 1;
    58.   row2 = 2;
    59.   row3 = 3;
    60.   rowE = 4;
    61.   rclk = 5;
    62.   clk  = 6;
    63.   rdat = 7;
    64.   gdat = 8;
    65.  
    66.   pinMode (row1, OUTPUT);
    67.   pinMode (row2, OUTPUT);
    68.   pinMode (row3, OUTPUT);
    69.   pinMode (rowE, OUTPUT);
    70.   pinMode (rclk, OUTPUT);
    71.   pinMode (clk , OUTPUT);
    72.   pinMode (rdat, OUTPUT);
    73.   pinMode (gdat, OUTPUT);
    74.   Shift = 0;
    75. }
    76.  
    77.  
    78. void DisplayClass::shift(){
    79.   for(int row=0;row<8;row++){
    80.     for(int col=0;col<50;col++){
    81.       rbitmap[row][col] = rmsgbitmap[row][(col+Shift)];
    82.       gbitmap[row][col] = gmsgbitmap[row][(col+Shift)];
    83.  
    84.      }
    85.   }
    86.   Shift++;
    87.   if(Shift==76){
    88.     Shift=0;
    89.   }
    90. }
    91.  
    92.  
    93.  
    I don't understand why the green would work but not the red. I almost immediately thought it was a hardware malfunction but I have thoroughly tested it, and it is not.
     
  9. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Interesting approach to use a bool array.

    But you hardcode the dimensions (even if you could use defines).

    What about this:


    • Bitmap memory organized as bytes or words.


    • blitting logic to copy parts of bitmap which is visible into display buffer memory


    • Display buffer memory
    • descriptor tables how the external hardware is mapped to I/O
    • code to copy parts from the display buffer to the I/O using the hardware descriptor tables
    It can be simple if you connect the matrix to full ports in ascending bit order. If you need to remap all the bits, it will be much slower.

    2

    Scrolling Once you have the code ready as described above, you precompute the whole string as bitmap. Advantage: you can use proportional fonts.

    then you treat it as bitmap, and copy a window to the display buffer.
    That window is shifted step by step.

    It is possible to do all the work on the Arduino, and just send the ASCII text.

    All you need to do is to realize the abstract associations (the message bitmap is copied together from the font bitmaps, then a window from the message bitmap is copied into the display buffer memory. Then the display buffer is transfered to I/O as required for instance multiplexing).

    I am for instance using a proportional font, where I store the width in the upper 3 bits of the first byte. Looks much much better than fixed width. If you compute it on the fly and the character width is variable, it become very hard to code that properly.
     
  10. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    I am a noob.

    I don't understand half of what you are saying. Especially under "What about this:"

    You're suggesting I send the text via serial and have the arduino do the rest?

    My goal was to have the large computing end be done by the computer in order to be less taxing on the arduino. That way all the arduino has to do is display, shift, and receive the data.

    Also I think I understand what you are saying about the proportional font with the size being stored in the three bits. I have spent literally hours and hours making that font and it seems a hassel to change it just to make it look prettier.

    I thought shift could be incorporated in the refresh function like thus:
    Code ( (Unknown Language)):
    1. if ((gbitmap [row][col+Shift]) == 1) {  //Communicate with Sign to display gbitmap
    2.          digitalWrite(gdat, HIGH);
    3.        }
    4.        else digitalWrite (gdat, LOW);
    That would get rid of the window bitmap all together.

    I am still however unsure why my red is displaying random garbage.
     
  11. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    yes making these fonts can be time consuming.

    Using C language means to learn how to apply abstraction to almost anything.

    Put simpler you can think like that:

    Existing data or input data

    Transition or transformation function

    Desired output


    Existing data: The font + the ASCII text

    Transformation function: the scrolling algorithm

    Desired output: A pattern scrolling through


    There is a deviation between the existing data, and the desired output.


    the idea is to transform it with as less effort as possible, and to optimize the program for some aspects such as readability, and maintainability.


    After a while, I just found it handy to precompute the bitmap for the whole string (the message), and then use a sliding window into an output buffer.


    1. how the output buffer (same size as actual matrix) is mapped, transfered or shown on the matrix is totally removed from the algorithm.

    2. How the font is structured also is removed from the algorithm- it just scrolls a bitmap


    You may get along with your approach after a while but maybe you want to change the size or build another matrix.

    Also precomputing the bitmap is reducing the amount of required processing power a lot.

    I have done a scrolling message for a 16F57 with 2K FLASH (12x5 matrix).

    that said I am working on a better 14x5 matrix powered by a 4K FLASH PIC, the 16f884.



    Maybe you want to know why the red LEDs dont work right.
    Breaking it down into independent pieces can help a lot to isolate the mistake.

    for instance, you can run the bitmap generator in a software simulator.

    I made the experience, rewriting a bad source can be easier than keep searching for errors.

    Of course, I did not say your source is bad. Just from experience, I normally dispose sources when I get stuck :)
     
  12. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    I don't quite understand what you mean by precomputing the bitmap.



    I think maybe I have failed to mention everything.

    I have written a console application that takes a string of characters that the user enters and writes it to a bitmap using a font that I have created.

    Since I have not created the link between the computer end and the arduino end. I just copied and pasted the msgbitmap that the computer creates.



    With that said I integrated my shift function into the refresh function and heavily commented my code.

    Here are the results:
    main.cpp:
    Code ( (Unknown Language)):
    1. /*50 X 8 Scrolling Matrix
    2.  Author: Kurt
    3. Date 2/14/14
    4. Version 2.0 */
    5.  
    6. #include "DisplayClass.h"
    7.  
    8. void setup(){
    9.   DisplayClass o;
    10.   o.Setup(); //Setup Pins and Set as OUTPUTS
    11.  
    12. }
    13.  
    14. void loop (){
    15.   DisplayClass o;
    16.   o.Setup();   //For Some Reason It does NOT work without this
    17.   while(1){
    18.     for(int Speed=0;Speed<10;Speed++){  //Speed of shifting
    19.     o.refresh();         //Display msgbitmaps windows
    20.     }
    21.     o.Shift++;          //increment shift
    22.   }
    23. }
    DisplayClass.cpp:
    Code (Text):
    1. #include "DisplayClass.h"
    2. #include "Arduino.h"
    3. /*Global msgbitmaps TEMPORARY*/
    4. bool rmsgbitmap [8][126] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    5.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    6.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    7.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    8.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    9.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    10.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    11.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    12.                      
    13. bool gmsgbitmap [8][126] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    14.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    15.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    16.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    17.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    18.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    19.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    20.                             {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
    21.  
    22.  
    23. void DisplayClass::refresh(){    //Display the bitmaps
    24.   for (int row=0; row<8; row++){ //Cycle through each row
    25.     digitalWrite (rowE, HIGH);   //Turn OFF display
    26.     digitalWrite (rclk, LOW);    //Turn OFF display
    27.  
    28.     for (int col=0; col < 50; col++){   //Cycle through columns
    29.       digitalWrite(gdat, LOW);       //Make sure dataPins are LOW
    30.       digitalWrite(rdat, LOW);       //MAke sure dataPins are LOW
    31.      
    32.        if ((gmsgbitmap [row][(col+Shift)]) == 1) {  //Communicate with Sign to display window of gmsgbitmap
    33.          digitalWrite(gdat, HIGH);
    34.        }
    35.        else digitalWrite (gdat, LOW);
    36.        
    37.        if ((rmsgbitmap [row][(col+Shift)]) == 1){  //Communicate with Sign to display windwo of rmsgbitmap
    38.          digitalWrite(rdat, HIGH);
    39.        }
    40.        else digitalWrite (rdat, LOW);
    41.      
    42.       digitalWrite(clk, HIGH); //increment clock
    43.       digitalWrite(clk, LOW);  //increment clock
    44.     }
    45.  
    46.     digitalWrite(rclk, HIGH);  //increment row clock
    47.     if bitRead(row,0) digitalWrite (row1, HIGH); else digitalWrite(row1, LOW); //Select Row to turn on for multiplexing
    48.     if bitRead(row,1) digitalWrite (row2, HIGH); else digitalWrite(row2, LOW);
    49.     if bitRead(row,2) digitalWrite (row3, HIGH); else digitalWrite(row3, LOW);
    50.     digitalWrite(rowE, LOW);  //Turn display On
    51.     delayMicroseconds(600);    //Rause for multiplexing
    52.   }
    53.   if(Shift==76){  //Reset shift to loop
    54.     Shift=0;
    55.   }
    56. }
    57.  
    58.  
    59. void DisplayClass::Setup(){
    60.   row1 = 1; //Set Arduino Pins
    61.   row2 = 2;
    62.   row3 = 3;
    63.   rowE = 4;
    64.   rclk = 5;
    65.   clk  = 6;
    66.   rdat = 7;
    67.   gdat = 8;
    68.  
    69.   pinMode (row1, OUTPUT); //Set Pins as OUTPUTS
    70.   pinMode (row2, OUTPUT);
    71.   pinMode (row3, OUTPUT);
    72.   pinMode (rowE, OUTPUT);
    73.   pinMode (rclk, OUTPUT);
    74.   pinMode (clk , OUTPUT);
    75.   pinMode (rdat, OUTPUT);
    76.   pinMode (gdat, OUTPUT);
    77.   Shift = 0;  
    78. }
    79.  
    80.  
    81.  
    82.  
    83.  
    84.  
    DisplayClass.h:
    Code (Text):
    1. #ifndef DISPLAYCLASS_H
    2. #define DISPLAYCLASS_H
    3.  
    4.  
    5. class DisplayClass
    6. {
    7.     public:
    8.       int row1; //binary value for row select
    9.       int row2; //binary value for row select
    10.       int row3; //binary value for row select
    11.       int rowE; // row enable enable display LOW ON
    12.       int rclk; // register clk latch
    13.       int clk; // serial clock input
    14.       int rdat; // red serial data
    15.       int gdat; // green serial date
    16.      
    17.       int Shift;
    18.      
    19.       bool  rbitmap [8][50]; //without this doesn't work
    20.       bool  gbitmap [8][50];
    21.      
    22.       void refresh();   //Display bitmaps
    23.       void Setup();     //Set up Arduino
    24.  
    25. };
    26.  
    27. #endif // DISPLAYCLASS_H
    It works for the most part displaying the message and shifting it appropriately.

    However, there are two peculiar things that don't quite work.

    1. Without rbitmap and gbitmap in DisplayClass.h It does not work at all. These arrays aren't even used. Why if I delete them does it refuse to function?

    2. For some reason row 1 (second from top), display random garbage. (see pic).
     
  13. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I understand your setup more now. You compute on the Windows PC, and then send raw data to the Arduino.

    One thing that totally springs into my eye is the way you make use of instances of your display class:

    Code ( (Unknown Language)):
    1.  
    2. DisplayClass o;
    3. o.Setup();
    1. the name "o" is not good but that does not matter.
    2. you create a local instance of "DisplayClass" in each function!
    that is not correct. You need one global instance of that class, and then you always need to work with that.

    3. What do you mean "does not function". i do not see these arrays refered at all. Do you get a compiler error, or it just does not work?

    Who knows. maybe Visual studio is stuck, and partiallly is refering to older instances of the sourcce.

    Clean the build.
    Do a debug run + single step with a suitable initial breakpoint.

    I am not a master for VS, but I do get along with it.

    4. If you do more work on the Arduino, you only need C, and no dealing with classes.

    It should become clear you need to create an instance from a class definition, and always work with the correct instance. You only create a static instance- normally with the Windows subsystem, dynamic instances of a class are created + memory is allocated (just mentioning it).

    You create temporary instances inside functions, these are discarded after leaving the function. It is a riddle it can do just anything that way.

    Particulary, correct the instancing issue, and tell us what happens if you comment the arrays in the class (i.e. what error message).
     
  14. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I was thinking you use a C++ based program on the PC but now it's clear you run it on Arduino.

    But the instancing issue is the same (creating local instance of a class inside function).

    Essentially you are aready precomputing the bitmap with the scrolling text.
     
  15. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    First I want to say Thank You for all your help so far it is much appreciated.

    I'm not sure if I know how to create a global instance. Do you just put it outside of a function like this:
    Code ( (Unknown Language)):
    1.  
    2. DisplayClass Obj;
    3. void loop(){
    4.      obj.refresh();
    5. ....
    6. }
    7.  
    If so I tried that way and when I ran it, it display random stuff on the first row.

    They are in DisplayClass.h:
    Code ( (Unknown Language)):
    1. #ifndef DISPLAYCLASS_H
    2. #define DISPLAYCLASS_H
    3.  
    4.  
    5. class DisplayClass
    6. {
    7.     public:
    8.    
    9.      
    10.    
    11.       int row1; //binary value for row select
    12.       int row2; //binary value for row select
    13.       int row3; //binary value for row select
    14.       int rowE; // row enable enable display LOW ON
    15.       int rclk; // register clk latch
    16.       int clk; // serial clock input
    17.       int rdat; // red serial data
    18.       int gdat; // green serial date
    19.      
    20.       int Shift;
    21.      
    22.       [COLOR="Red"]bool  rbitmap [8][50]; //without this doesn't work
    23.       bool  gbitmap [8][50];[/COLOR]
    24.      
    25.       void refresh();   //Display bitmaps
    26.       void Setup();     //Set up Arduino
    27.  
    28. };
    #endif // DISPLAYCLASS_H

    I put them in a red. When I run it with them commented out it simply does not display anything at all.


    I am working in Arduino's compiler.
    I copied everything into a new sketch and deleted all my builds in C:\Users\Kurt\AppData\Local\Temp\ as that is where the Arduino compiler said they are stored.

    The same results as before occurred
    1. Garbage on the second line as shown in previous picture.

    2. Will not display anything if gbitmap and rbitmap in DisplayClass.h are commented out.

    P.S. I thought maybe the garbage in row 2 was from something with the bitmap so I set up a for loop to set all elements to zero. The result did not change at all

    P.S.S I also tried getting rid of my classes and putting everything in one file. I did not like how it looked at all. And it did not display anything at all either.
     
    Last edited: Feb 14, 2014
  16. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    you don't have to use classes, as C++ contains C language.

    Did you write all the code yourself?

    It is often hard to find errors in code which has multiple issues.

    the schematic for the matrix also is not clear.


    What about lightening up one line, and then gain control over that, so you can move the line which lights up slowly?

    Then you know your software/IO interface works.


    Another idea is to use whole bytes vertically. Then you'd copy from the bitmap into a display buffer, exactly as large as the matrix.

    that is not too hard.

    when you gained control how to light a single line, it is also not too hard to copy the display buffer to the matrix.

    2

    Searching bugs is OK, I found it time saving just to rewrite everything, and if possible, test out each function somehow.


    Does the Arduino IDE have a debugger, or software simulator?


    3

    If possible really show the complete code, for instance, use a wordpress blog (altervista free hosting).


    4

    The question is really if you wrote all the lines from scratch, as you ask questions about them like if you weere not totally sure what the lines are doing.

    I am pretty sure you need to use a global instance of the display class, and just one.

    Sorry for mixing it up with Visual Studio :)
     
  17. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    I have written all the code myself this is really version 2.0 the first version I made had no interface with the computer at all and no proportional font.

    I like organizing my functions into classes.

    I'm going do some multiplexing detective work as suggested.

    I will probably scrap all my code except my font and start over. I don't like how it was turning out anyway.
     
  18. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    I am having trouble once again this time on the computer end.

    Here's the code:

    Code ( (Unknown Language)):
    1. #ifndef DISPLAYFUNCTIONS_H
    2. #define DISPLAYFUNCTIONS_H
    3.  
    4.  
    5. class DisplayFunctions
    6. {
    7.     public:
    8.         int rmsgByteMap[];
    9.         int gmsgByteMap[];
    10.  
    11.         char msg [512];
    12.         int numberOfCol;
    13.         int msgLength;
    14.         int characterArrayLength[];
    15.  
    16.  
    17.         void getMsg();   //get the users message
    18.         void createByteMap();  //Create array of msg
    19.         void send();     //Send users message via serial
    20. };
    21.  
    22. #endif // DISPLAYFUNCTIONS_H
    23.  
    Code ( (Unknown Language)):
    1. #include "DisplayFunctions.h"
    2. #include <iostream>
    3. #include <string>
    4. #include <cstdlib>
    5. #include <ctime>
    6. #include<stdio.h>
    7. #include<conio.h>
    8. #include "Font.h"
    9. using namespace std;
    10.  
    11. Font fontObj;
    12.  
    13. void DisplayFunctions::getMsg(){
    14.  
    15.     int characterLength;
    16.     cin.getline(msg, 512);
    17.  
    18.     for(msgLength = 0; msg[msgLength] != '\0'; msgLength++);  //increment msgLength until null terminal
    19.  
    20.     characterLength = 0;
    21.     numberOfCol = 0;        
    22.  
    23.     for(int character = 0; character < msgLength; character++){          //ArrayLength for each character
    24.         for(int i=0; i < 8; i++){
    25.  
    26.             if (fontObj.ASCII[(msg[character])][i] != 256){                 //if egual to 256 (which is invalid) then don't increment array length
    27.  
    28.                     characterLength++;
    29.             }
    30.         }
    31.         characterArrayLength[character] = characterLength;   //Length of each Character in the Message
    32.  
    33.  
    34.         numberOfCol += characterLength;                                      //number of columns
    35.  
    36.         characterLength = 0;    //Reset arrayLength
    37.     }
    38.  
    39. }
    40.  
    41. void DisplayFunctions::createByteMap(){
    42.     int charColIndex =0;
    43.     int Character = 0;
    44.  
    45.  
    46.     for(int col=0;col<numberOfCol;col++){
    47.             rmsgByteMap[col] = fontObj.ASCII[msg[Character]][charColIndex];
    48.             charColIndex++;
    49.             if (charColIndex==characterArrayLength[Character]){
    50.                 charColIndex = 0;
    51.                 Character++;
    52.             }
    53.  
    54.  
    55.  
    56.  
    57.     }
    58.    
    59. }
    60.  
    61.  
    62.  
    63.  
    64.  
    65. [/i]



    It seems as if whenever I access the msg which is a char array it deletes the entire array. I tired to bypass this by passing in the msg to another array, but it makes no difference.

    Let me explain further.
    After I have run getMsg and createByteMaps if I do this:
    Code ( (Unknown Language)):
    1.  
    2. cout << msg[0] << " ";
    3. cout << msg[1] << " ";
    4. cout << msg[2] << " ";
    5. cout << msg[3] << " ";
    6. cout << msg[4] << " ";
    7. ....
    8.  
    9.  
    10.  
    It will display .
    Literally nothing.
    Why is this?
    I have not changed the array at all I have only accessed it.


    This is really perturbing.
     
  19. kurtruk

    Thread Starter Member

    Aug 26, 2012
    140
    6
    Does anyone have any idea?

    I've now tried numerous ways.

    For example I created a function to return the char. and then used that in the loop, but it doesn't work either.

    does anyone know what my problem is?
     
  20. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    684
    92
    Nevermind nevermind
     
    Last edited: Feb 17, 2014
Loading...