Inspiration: This is a very special project that I made because I saw a dearth of a digitized version of a name plate that exists on virtually everyone's office desk. **** I will share the procedure and library modifications I did (and small code snippets) while building the project **** Here's how it looks all done. Key Features:
Displaying Random Animations on LED Matrix Display: You can download the source code for displaying animations here Here are some picture of the final product:
More Pics can be found here Key things to remember while doing a project similar to this:
Code snippet : // Using the font libraries to display text on LED Matrix Display // www.kunaldoshi.com void drawString(uint8_t x, uint8_t y, char* c,uint8_t font_size,boolean update_s) { // x & y are positions, c-> pointer to string to disp, update_s: false(write to mem), true: write to disp //font_size : 51(ascii value for 3), 53(5) and 56(8) for(char i=0; i< strlen(c); i++) { drawChar(x, y, c[i],font_size,update_s); x+=calc_font_displacement(font_size); // Width of each glyph } } int calc_font_displacement(uint8_t font_size) { switch(font_size) { case 51: return 4; //5x3 hence occupies 4 columns ( 3 + 1(space btw two characters)) break; case 53: return 6; break; case 56: return 6; break; default: return 6; break; } } void drawChar(uint8_t x, uint8_t y, char c, uint8_t font_size,boolean update_s) // Display the data depending on the font size mentioned in the font_size variable { uint8_t dots; if (c >= 'A' && c <= 'Z' || (c >= 'a' && c <= 'z') ) { c &= 0x1F; // A-Z maps to 1-26 } else if (c >= '0' && c <= '9') { c = (c - '0') + 27; } else if (c == ' ') { c = 0; // space } else if (c == '#'){ c=37; } else if (c=='/'){ c=37; } switch(font_size) { case 51: // font size 3x5 ascii value of 3: 51 for (char row=0; row< 5; row++) { dots = pgm_read_byte_near(&font3x5[c][row]); for (char col=0; col < 3; col++) { uint8_t x1=x; uint8_t y1=y; if (dots & (4>>col)) toolbox.setPixel(x1+col, y1+row, 1,update_s); else toolbox.setPixel(x1+col, y1+row, 0,update_s); //Serial.println(x1,y1); } } break; case 53: // font size 5x5 ascii value of 5: 53 for (char row=0; row< 5; row++) { dots = pgm_read_byte_near(&font5x5[c][row]); for (char col=0; col < 5; col++) { uint8_t x1=x; uint8_t y1=y; if (dots & (64>>col)) // For some wierd reason I have the 5x5 font in such a way that.. last two bits are zero.. // dots &64(10000000) gives info regarding the first bit... // dots &32(01000000) gives info regarding second bit and so on... toolbox.setPixel(x1+col, y1+row, 1,update_s); else toolbox.setPixel(x1+col, y1+row, 0,update_s); } } break; case 56: // font size 5x8 ascii value of 3: 56 for (char col=0; col< 5; col++) { dots = pgm_read_byte_near(&font5x8[c][col]); for (char row=0; row < 8; row++) { uint8_t x1=x; uint8_t y1=y; if (dots & (64>>row)) // dots &64(10000000) gives info regarding the first bit... // dots &32(01000000) gives info regarding second bit and so on... toolbox.setPixel(x1+col, y1+row, 1,update_s); else toolbox.setPixel(x1+col, y1+row, 0,update_s); } } break; default: break; } } |