Faster way to copy then getting and setting? getPixel(num) to setPixel(num, color)

Status
Not open for further replies.

dirkblaze

Member
See Below!

#define LED_WIDTH 50 // number of LEDs horizontally
#define LED_HEIGHT 16 // 16 rows of 50!
#define LED_LAYOUT 1 // 0 = even rows left->right, 1 = even rows right->left
#define VIDEO_XOFFSET 20 //<< Let's try this:
#define VIDEO_YOFFSET 20 //<< 1/4 in
#define VIDEO_WIDTH 30 //<< the center 1/2 or so
#define VIDEO_HEIGHT 30 //<< of the video

const int ledsPerStrip = LED_WIDTH * LED_HEIGHT ; // All LEDs on one wire for now!!

DMAMEM int displayMemory[ledsPerStrip*6];

byte IncomingFrame[ledsPerStrip*3+6];

const int config = WS2811_800kHz; // color config is on the PC side

OctoWS2811 leds(ledsPerStrip, displayMemory, NULL, config);

void setup() {
pinMode(12, INPUT_PULLUP); // Frame Sync
Serial.setTimeout(50);
leds.begin();
leds.show();

SetAllPixels(BLACK); // Display some text on the array
TextMeLeft((byte *) "Happy pi Day ",13);
delay(3000);

}

Proc TextMeLeft( byte message[], int count) paints ascii text on the matrix using a set of 8x8 font masks (not shown). It paints in the rightmost column and calls ScrollLeft() to "move" the characters across the matrix.

ScrollLeft() below moves a section of the array "to the left" one column, opening an empty space at the far right It uses getPixel to get the color from one column and setPixel to place it in the next.

This is a ok but just a little slow, probably about 25hz.



void ScrollLeft() // open a space at the end of the display, scroll left one column
// Copy all the columns from the end (NUM_COLS) towards the begining (0)
{
int j, j1;

for (int toCol = 0 ; toCol < NUM_COLS; toCol++) // Start at col 0 - we loose the val of that column
{
for (int toRow = 2; toRow < 10; toRow +=2) // Each Row in curent column (toCol) gets val of col to left
{

// j and j1 are where to put the color in the even and odd rows

j = NUM_COLS*toRow+toCol; // increasing index, j = even rows
j1 = ((NUM_COLS*(2+toRow))-toCol)-1; // decreasing index, j1 = odd rows

// Now copy the prior column (to the right) into the current column, thus moving the display one column to the left...

// This is pretty slow; is there a faster way? DMA?

leds.setPixel(j, leds.getPixel(j+1)); // even row: 0, 2, 4... Move the color one column left
leds.setPixel(j1, leds.getPixel(j1-1)); // odd row: 1, 3, 5...

}
}
}


To scroll the display as it's painted, ScrollLeft is called, the column is painted, then show() is called. The code below works but is not completely optimized.


void TextMeLeft( byte message[], int count)
{
// Display characters of message scrolling left
// Push text in from the left to the right a column at a time

int CharBitCol;
int pixelRow ;
int pixelCol = 1;
int thisChar;
int thisColor;
byte thisByte;


for (int i = 0; i < count; i++) // Paint characters
{
thisChar = ((int)message); // The character to display next mapped to 8x8 dot matrix index
if ((thisChar > 47) and (thisChar < 58)) thisColor = JodyColor[thisChar- 48]; else thisColor = WHITE;
thisChar = (((int)message)-32)*8; // The character to display next mapped to 8x8 dot matrix index
CharBitCol = 7; // Start in bit column 7 from matrix
for (pixelCol = 8; pixelCol >1; pixelCol--)
{

ScrollLeft(); // open a space at the end of the display for next column of new char

for (pixelRow = 1; pixelRow < 9; pixelRow ++) // 8 rows of the display, 8 rows of the char matrix
{ // light column by column
thisByte = CharBMap[thisChar+pixelRow]; // Correct row of the char matrix

if((thisByte & ColMask[CharBitCol]) != 0)
leds.setPixel(PixelMap(NUM_COLS-1, pixelRow+1), thisColor);
else // Always paint in the last column, will push left
leds.setPixel(PixelMap(NUM_COLS-1,pixelRow+1), BLACK);
} // the rows of this column

leds.show();
CharBitCol--;
} // the columns of this char
} // thisChar
} // TextMeLeft ()



How to make the ScrollLeft() proc faster? Faster way to copy the color, pixel to pixel?
 
Status
Not open for further replies.
Back
Top