Advertisement
TolentinoCotesta

Big number example

May 10th, 2020
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.19 KB | None | 0 0
  1. // include the library code:
  2. #include <LiquidCrystal.h>
  3.  
  4. // initialize the library with the numbers of the interface pins
  5. LiquidCrystal lcd(12, 11, 10, 9, 8, 7);                              
  6.  
  7.  
  8. #define UP   2
  9. #define DOWN 3
  10. unsigned int counter = 0;
  11.  
  12.  
  13. //************************************************************************
  14. //*  A set of custom made large numbers for a 16x2 LCD using the
  15. //*  LiquidCrystal librabry. Works with displays compatible with the
  16. //*  Hitachi HD44780 driver.
  17. //*  LT= left top
  18. //*  UB= upper bar
  19. //*  RT= right top
  20. //*  LL= lower left
  21. //*  LB= lower bar
  22. //*  LR= lower right
  23. //*  UMB= upper middle bars(upper middle section of the '8')
  24. //*  LMB= lower middle bars(lower middle section of the '8')
  25. const uint8_t gBigFontShapeTable[] PROGMEM = {
  26.  B00111, B01111, B11111, B11111, B11111, B11111, B11111, B11111,  // LT[8]
  27.  B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000,  // UB[8]
  28.  B11100, B11110, B11111, B11111, B11111, B11111, B11111, B11111,  // RT[8]
  29.  B11111, B11111, B11111, B11111, B11111, B11111, B01111, B00111,  // LL[8]
  30.  B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111,  // LB[8]
  31.  B11111, B11111, B11111, B11111, B11111, B11111, B11110, B11100,  // LR[8]
  32.  B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111,  // UMB[8]
  33.  B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111   // LMB[8]
  34. };
  35.  
  36. //*  6 numbers for each character
  37. const uint8_t gBigFontAsciiTable[] PROGMEM = {
  38.  0, 1, 2, 3, 4, 5,      // 0x30 0
  39.  1, 2, 32, 4, 5, 4,     // 0x31 1
  40.  6, 6, 2, 3, 7, 7,      // 0x32 2
  41.  1, 6, 2, 7, 7, 5,      // 0x33 3
  42.  3, 4, 2, 32, 32, 5,    // 0x34 4
  43.  0, 6, 6, 7, 7, 5,      // 0x35 5
  44.  0, 6, 6, 3, 7, 5,      // 0x36 6
  45.  1, 1, 2, 32, 0, 32,    // 0x37 7
  46.  0, 6, 2, 3, 7, 5,      // 0x38 8
  47.  0, 6, 2, 32, 32, 5     // 0x39 9
  48. };
  49.  
  50.  
  51. //************************************************************************
  52. void  BigNumber_SendCustomChars(void){
  53.   uint8_t  customCharDef[10];
  54.   uint8_t  ii, jj;
  55.   for (ii=0; ii<8; ii++) {
  56.     for (jj=0; jj<8; jj++) {
  57.       customCharDef[jj]  =  pgm_read_byte_near(gBigFontShapeTable + (ii * 8) + jj);
  58.     }
  59.     lcd.createChar(ii, customCharDef);    
  60.   }
  61.  
  62. }
  63.  
  64. //************************************************************************
  65. void  DrawBigChar(int xLocation, int yLocation, char theChar){
  66. int   offset, ii;
  67. char  theByte;
  68.   offset   =  6 * (theChar - 0x30);
  69.   lcd.setCursor(xLocation, yLocation);
  70.   for (ii=0; ii<3; ii++) {
  71.     theByte  =  pgm_read_byte_near(gBigFontAsciiTable + offset + ii);
  72.     lcd.write(theByte);
  73.   }
  74.  
  75.   lcd.setCursor(xLocation, yLocation + 1);
  76.   offset += 3;
  77.   for (ii=0; ii<3; ii++) {
  78.     theByte  =  pgm_read_byte_near(gBigFontAsciiTable + offset + ii);
  79.     lcd.write(theByte);
  80.   }  
  81. }
  82.  
  83.  
  84. void setup() {
  85.     Serial.begin(9600);
  86.     pinMode(UP,   INPUT_PULLUP);
  87.     pinMode(DOWN, INPUT_PULLUP);
  88.  
  89.     lcd.begin(16, 2);
  90.     lcd.print("Start...");
  91.     delay(1000);
  92.     lcd.clear();
  93.     BigNumber_SendCustomChars();
  94. }
  95.  
  96.  
  97. void loop() {
  98.     Serial.print(F("Counter value : "));
  99.     Serial.println(counter);  
  100.     DrawBigChar(4, 0, 0x30+counter);
  101.     DrawBigChar(8, 0, 0x30+counter);
  102.     counter = (++counter) % 10;
  103.     delay(1000);  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement