title: Arduino: Printing ASCII characters to LEDs / pointer weirdness
body: <p>I've made a 24 x 15 LED matrix using TLC5940s and shift registers, running on an Arduino Due.</p>
  
  <p>First thing first, I want to print an ASCII char, eg. 'A' directly to the display.</p>
  
  <p>So I stored a font array in PROGMEM, using <a href="https://stackoverflow.com/questions/2912961/ascii-7x5-side-feeding-characters-for-led-modules">a link I found</a> :</p>
  
  <pre><code> PROGMEM prog_uchar font[][5] = {
      {0x00,0x00,0x00,0x00,0x00},   //   0x20 32
      {0x00,0x00,0x6f,0x00,0x00},   // ! 0x21 33
                  ...
      {0x08,0x14,0x22,0x41,0x00},   // &lt; 0x3c 60
      {0x14,0x14,0x14,0x14,0x14},   // = 0x3d 61
      {0x00,0x41,0x22,0x14,0x08},   // &gt; 0x3e 62
      {0x02,0x01,0x51,0x09,0x06},   // ? 0x3f 63
                  etc.
  </code></pre>
  
  <p>Now, the weird part, is that everything almost works, but is shifted slightly.
  For example, '>' gets morphed to this:</p>
  
  <pre><code>00000000      --&gt;     00001000    
  01000001      --&gt;     00000000
  00100010      --&gt;     01000001
  00010100      --&gt;     00100010
  00001000      --&gt;     00010100
  </code></pre>
  
  <p>So i think it is a pointer boundary issue.  Maybe I've just been looking at it for too long, but I don't know!</p>
  
  <p>Here is the relevant code, where I've hardcoded the values for '&lt;'.  I did a Serial.println, and it is showing the correct value for 'b'.  x and y are 0 and 0, to place the character in the corner.  The commented-out assignment of 'b' is what I usually do, instead of hardcoding.  charWidth = 5 and charHeight = 7.  setRainbowSinkValue(int led, int brightness) has worked forever, so it's not that.</p>
  
  <pre><code>  unsigned char testgt[]   = {0x00,0x41,0x22,0x14,0x08};
  
    for (int iterations = 0; iterations &lt; time; iterations++)
    {
  
      unsigned char indexOfWidth = 0;
      unsigned char indexOfHeight = 0;
  
      for (int col = x; col &lt; x + charWidth; col++) 
      {
          openCol(col);      
          Tlc.clear(); 
          unsigned char b = testgt[indexOfWidth];//pgm_read_byte_near(font[ch] + indexOfWidth );
  
            //Serial.println(b);
  
          indexOfHeight = 0;
          for (int ledNum = y; ledNum &lt; y + charHeight; ledNum++)
          {
            if (b &amp; (1 &lt;&lt; indexOfHeight))
            {
              setRainbowSinkValue(ledNum, 100);
            }
            indexOfHeight++;
          }
  
          indexOfWidth++;
          Tlc.update(); 
      }
    }
  </code></pre>
  
  <p>Can you see anything wrong?  The most likely issue is the bit operations, but it makes sense... 
  b &amp; 1...
  b &amp; 2...
  b &amp; 4... 
  b &amp; 8... 
  b &amp; 16... 
  b &amp; 32... 
  b &amp; 64... 
  b &amp; 128... </p>