Additions to your very useful uvga class

Posted by Dustintweir on Tue 11 Mar 2014 07:47 PM — 2 posts, 12,181 views.

#0
Thanks for the great library for operating my micro vga. I've been using mine to paint terminal screens compressed and stored in the Arduino's EEPROM. I've stored these "templates" as strings of ASCII codes starting at address 0 in the EEPROM, and ending with EOF character 034. This assumes the strings are in left-to-right, top-down order in the EEPROM up to the screen size of 2,000 characters.

To save memory, any time I have 4 or more identical characters to print I add character 021, followed by the repeat character, followed by the quantity of repeats. Finally I return the memory index of the first character after EOF, so I can re-call the function to read the next screen.


Used in sketches

int ROMScreen(int index)
{
  byte buf, character; //incoming character and repeating character storage
  int quantity; //number of character repeats
  uvga.gotoxy(1,1);
  
  do{
    buf = EEPROM.read(index); //read current byte
    if (buf == 21){ //indicates repeating character
      index++;
      character = EEPROM.read(index); //read the character to be repeated
      index++;
      quantity = EEPROM.read(index); //read the quantity of repeats
      if (character==255) //special character to indicate "don't write anything"
        uvga.advance(quantity);
      else 
        for (int i=0; i<quantity; i++){
          uvga.write(character);
        }
    }
    else if (buf != 34){ //non-repeating but not EOF
      if (buf == 255)
        uvga.advance(1);
      else
        uvga.write(buf);
    }
    index++;   
  } while (buf != 34); //continue to read until EOF

  return index;
  
}


Finally, I added a function to advance the cursor a number of places without moving the cursor to each place. This greatly speeds paint time

To uvga.h, line 93

void advance (char i);

To uvga.cpp, at the end of the file

void uVGA::advance (char i)
{
	write (ESC "[");
	write ((i / 100)+'0');
	i = i-(i/100)*100;
	write ((i / 10) + '0');
	write ((i % 10) + '0');
	write ('C');

}

USA Global Moderator #1
Template:Arduino
Please post Arduino-related questions to the Arduino Forum or to StackExchange: Arduino. This saves splitting questions and answers between this forum and the Arduino ones.