Go Down

Topic: How to get Font from EEPROM (Read 2525 times) previous topic - next topic


Oct 02, 2012, 02:10 pm Last Edit: Oct 02, 2012, 02:25 pm by taipscode Reason: 1
Hello every boby.

Code: [Select]
for (byte c=0; c<8; ++c) {          
    for (byte y=0; y<8; ++y) {
           byte data = (byte) pgm_read_byte (&myfont[disp[line][c]][y]);   // fetch data from program memory
             for (byte x=0; x<8; ++x) {
               if (data & (1<<x)) {
                  // on is off
                  int color = 2;
                  if (line > 1)
                    color = 1;
                  set_pixel((7-x) + (line * 8),y + (c*8),color);
               } else {


This is available code ,which i downloaded ,but i don't know how to use detail this syntax :
data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])
This code is so complex ,can you give me some codes simpler ,because i search on Google serveral days ,but difficult to found  =( =(




It's difficult to help with just a code snipped. Please post all the info you have, especially what you're trying to achieve.


Yes,this is a full source.pde



Have you noticed this line in font.h ?

Code: [Select]

const prog_uint8_t PROGMEM BitMap[8] = {                                   // Store in program memory to save RAM

PROGMEM is where the program(!) is stored. RAM and EEPROM are other two types of memory you find in Arduino (well, inside the Atmega328P, actually).

pgm_read_byte is a special function that reads a byte from PROGMEM and brings it into RAM, so it can be used by the program.

I won't repeat here with my own (poor) words what has already been written elsewhere in great detail. Search for PROGMEM.



I only want how to use this syntax
data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])

not const prog_uint8_t PROGMEM BitMap[8] = {



Please read my previous reply.

Also, I don't find it clear what you're trying to do...


Yes, i hope you don't reply with not useful  :0



Oct 02, 2012, 02:55 pm Last Edit: Oct 02, 2012, 03:01 pm by tuxduino Reason: 1
That's the wrong smiley to use when asking for FREE help.

Good luck with your project.

(edit: maybe you misunderstood my previous answer: what I meant is that I don't understand what you're trying to achieve; it wasn't a judgement about your project (which I don't know))


I only want how to use this syntax
data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])

not const prog_uint8_t PROGMEM BitMap[8] = {

pgm_read_byte() is a function in the Arduino library.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)


I think it is general avr-libc, rather that Arduino specific.



data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])

data = (get 8 pixels ) from (a font-character[pointed to by disp[currentline][current_character][current_character_pixel_line].

Which is a complicated way of Saying

if disp[line] = "A simple test"
then disp[line][0] = "A"
      disp[line][1] = " "
      disp[line][2] = "s"
      ... etc

then &myfont[] returns the address of a character inside a font array which holds the (8 x 8 pixels) character.
So &myfont[disp[line][0]] would return the address to the letter "A" in the font array.

&myfont[disp[line][0]][y] would return 8 pixels of row [y] of the letter "A"
This technique is used to convert a letter to pixels. e.g. (8x8 pixel font)

.  .  .  .  .  .  .  .
.  .  .  X  .  .  .  .
.  .  X  .  X  .  .  .
.  X  .  .  .  X  .  .       =>  A
.  X  X  X  X  X  .  .
X  .  .  .  .  .  X  .
X  .  .  .  .  .  X  .
.  .  .  .  .  .  .  .

It's reading 8 pixels as a byte.
Your code then loops through this code with for (byte x=0; x<8; ++x)
And draws a pixel on the screen if it found a pixel in the font.

Thats about it.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131