Can someone explain the coding for the bargraph for me. This code snip comes from the line follow demo code.
// Data for generating the characters used in load_custom_characters
// and display_readings. By reading levels[] starting at various
// offsets, we can generate all of the 7 extra characters needed for a
// bargraph.
const char levels[] PROGMEM = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
// This character is a back arrow.
const prog_char back_arrow[] PROGMEM = {
0b00000,
0b00010,
0b00001,
0b00101,
0b01001,
0b11110,
0b01000,
0b00100,
};
//-------------------------------------------------------------------------------
// This function loads custom characters into the LCD. Up to 8
// characters can be loaded; we use them for 6 levels of a bar graph
// plus a back arrow and a musical note character.
//-------------------------------------------------------------------------------
void load_custom_characters()
{
lcd_load_custom_character(levels+0,0); // no offset, e.g. one bar
lcd_load_custom_character(levels+1,1); // two bars
lcd_load_custom_character(levels+2,2); // etc...
lcd_load_custom_character(levels+4,3); // skip level 3
lcd_load_custom_character(levels+5,4);
lcd_load_custom_character(levels+6,5);
lcd_load_custom_character(back_arrow,6);
lcd_load_custom_character(note,7);
clear(); // the LCD must be cleared for the characters to take effect
}
The other question is: how do I need to rewrite the function load_custom_characters() if I don’t load the variable levels[] into the PROGMEM?
Looking forward to your advise. Thanks!