Converting to progmem


i converting sketch uno mega , move font progmem.

i pretty sure got part right. note doesn't list 95 lines of font exceeded size post here shortened it.

code: [select]


// =====================================================================================================
// font definition
// =====================================================================================================
const unsigned char font8x8_basic[95][8] progmem= {
  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},   // ascii ( )
  {0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04, 0x00},   // ascii (!)
  {0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00},   // ascii (")
  {0x14, 0x14, 0x3e, 0x14, 0x3e, 0x14, 0x14, 0x00},   // ascii (#)
  {0x08, 0x3c, 0x0a, 0x1c, 0x28, 0x1e, 0x08, 0x00},   // ascii ($)
  {0x06, 0x26, 0x10, 0x08, 0x04, 0x32, 0x30, 0x00},   // ascii (%)
  {0x0c, 0x12, 0x0a, 0x04, 0x2a, 0x12, 0x2c, 0x00},   // ascii (&)

snip




but having trouble on how correct function uses table above


code: [select]


// =====================================================================================================
// ~~~ start of display text ~~~
// ----------------------------------
//   takes string of text , displays 1 character @ time each new word random colour
// =====================================================================================================
void displaysometext(string sometext, int pausetime) {
  byte achar;                                 // grabs 1 character @ time message string
  int  stringlen;                             // length of text message
  byte mycolour;                              // random colour
 
  uint16_t charscroll[8] = {0x0000, 0x0000,   // 8 row 16 bit display buffer
                            0x0000, 0x0000,   // 8x8 panel maps 8 msb's
                            0x0000, 0x0000,   // achar loads 8 lsb's
                            0x0000, 0x0000};  // bit shifts left scroll new char in , old char out
     
  stringlen = sometext.length();              // find length of text message
  mycolour = random(7) + 1;                   // select first random colour

  for(int = 0; < stringlen; i++){         // loop many characters in text message
    achar = int(sometext[i] - 0x20);          // ascii value each character , remove offset
   
    // load character buffers 8 least significant bits
    for(int j = 0; j < 8; j++){
      charscroll[j] += font8x8_basic[achar][7 - j] << 8;
    }
   
    // shift buffer left 1 bit load shift registers buffers 8 significant bits
    for(int j = 0; j < 7; j++){
      for(int k = 0; k < 8; k++){
        charscroll[k] = charscroll[k] >> 1;
        if(mycolour & 0x01) {shiftregisterred[k] = 0x00ff & charscroll[k];} else {shiftregisterred[k] = 0;}
        if(mycolour & 0x02) {shiftregistergrn[k] = 0x00ff & charscroll[k];} else {shiftregistergrn[k] = 0;}
        if(mycolour & 0x04) {shiftregisterblu[k] = 0x00ff & charscroll[k];} else {shiftregisterblu[k] = 0;}
      }
      delay(60);
    }
    // if space detected chose new random colour next word
    if(achar == 0x00){ mycolour = random(7) + 1; }
  }
delay(1000);
}
// ================================
// ~~~ end of display text ~~~
// ================================





i pretty sure line need change not sure how deal 8 bytes per character.


code: [select]

    // load character buffers 8 least significant bits
    for(int j = 0; j < 8; j++){
      charscroll[j] += font8x8_basic[achar][7 - j] << 8;
    }

step one, drop string... make things terrible complicated (while not knowing do).

and retrieve data progmem, use pgm_read_byte() (and don't forget include avr/pgmspace.h)
see http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html


Arduino Forum > Using Arduino > Programming Questions > Converting to progmem


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor