Publicidade:

quinta-feira, 15 de outubro de 2015

Arduino - LCD Big Numbers

Esse post demonstra vários exemplo de como gerar números grandes em displays LCD. Mais abaixo tem um exemplo de como utilizar mais de 8 caracteres customizáveis e ao final mostro um exemplo de um relógio em display LCD com números grandes.

São vários exemplos diferentes.

Vídeo 01:



Vídeo 02:


Código-fonte da primeira versão:

/*
Fabiano A. Arndt - 2015
www.youtube.com/user/fabianoallex
www.facebook.com/dicasarduino
fabianoallex@gmail.com
*/
   
#include <LiquidCrystal.h>
   
/*************************************************************************************************************
*******************************CLASSE LCD BIG NUMBERS*********************************************************
**************************************************************************************************************/
struct LCDNumber {
  byte top;
  byte bottom;
};
 
class LCDBigNumbers {
  private:
    LiquidCrystal * _lcd;
    int _row;
    int _col;
    long _value; /*0..100*/
     
    void _clear(){
      int cont = 1;
      long x = 9;
      while (_value > x){
        cont++;
        x = x * 10 + 9;
      }
      for (int i=0; i<cont; i++) {
        _lcd->setCursor(_col+i, _row);
        _lcd->print( " " );
        _lcd->setCursor(_col+i, _row+1);
        _lcd->print( " " );
      }
    }
  public:
    static byte c0[8];  
    static byte c1[8];  
    static byte c2[8];  
    static byte c3[8];
    static byte c4[8];
    static byte c5[8];  
    static byte c6[8];  
    static byte c7[8];  
    static LCDNumber _lcd_numbers[];
    
    void createChars() {
      _lcd->createChar(0, c0);
      _lcd->createChar(1, c1);
      _lcd->createChar(2, c2);
      _lcd->createChar(3, c3);
      _lcd->createChar(4, c4);
      _lcd->createChar(5, c5);
      _lcd->createChar(6, c6);
      _lcd->createChar(7, c7);
    }
     
    LCDBigNumbers(LiquidCrystal * lcd, int row, int col) {
      _lcd = lcd;      _row = row;      _col = col;
    }
     
    void setRow(int row){
      _clear();
      _row = row;
      setValue(_value);
    }
    void setCol(int col){
      _clear();
      _col = col;
      setValue(_value);
    }
     
    void setValue(long value){
      _clear();
      _value = value;
       
      int cont = 1;
      long x = 9;
      while (abs(_value) > x){
        cont++;
        x = x * 10 + 9;
      }
       
      for (int i=0; i<cont; i++) {
        int n = value / pow(10, cont-1-i);
        value = value - pow(10, cont-1-i) * n;
         
        _lcd->setCursor(_col+i, _row);
        _lcd->write( _lcd_numbers[n].top );
        _lcd->setCursor(_col+i, _row+1);
        _lcd->write( _lcd_numbers[n].bottom );
      }
       
    }
};

byte LCDBigNumbers::c0[8] = {B11111, B10001, B10001, B10001, B10001, B10001, B10001, B10001};
byte LCDBigNumbers::c1[8] = {B10001, B10001, B10001, B10001, B10001, B10001, B10001, B11111};
byte LCDBigNumbers::c2[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B00001};
byte LCDBigNumbers::c3[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111};
byte LCDBigNumbers::c4[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111};
byte LCDBigNumbers::c5[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B00001};    
byte LCDBigNumbers::c6[8] = {B11111, B10001, B10001, B10001, B10001, B10001, B10001, B11111};              
byte LCDBigNumbers::c7[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B11111};


LCDNumber LCDBigNumbers::_lcd_numbers[] = { 
  {0, 1}, //0
  {2, 2}, //1
  {5, 4}, //2
  {3, 7}, //3
  {1, 2}, //4
  {4, 7}, //5
  {4, 1}, //6
  {5, 2}, //7
  {6, 1}, //8
  {6, 7} // 9
};
 

/*************************************************************************************************************
*******************************FIM CLASSE LCD BIG NUMBERS*****************************************************
**************************************************************************************************************/
   
   
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LCDBigNumbers lcdNum(&lcd, 0,0); //inclui uma barra no lcd, primeira linha, coluna 8. tamanho 8
   
void setup()   {
  Serial.begin(9600);
  lcdNum.createChars();
  pinMode(44, OUTPUT);
  analogWrite(44, 255/6); //utilizado para aumentar o contraste
  lcd.begin(16, 2);
}
 
long i = 0;
int col = 0;
 
void loop() {
  lcdNum.setValue(i++ * 11);
   
  if (i>=10000) i = 0;
   
  if (i%10 == 0){
    lcdNum.setCol(col++);
    if (col >= 10){
      col = 0;
    }
  }
   
  delay(500);  
}


Código segunda versão:

 /*
Fabiano A. Arndt - 2015
www.youtube.com/user/fabianoallex
www.facebook.com/dicasarduino
fabianoallex@gmail.com
*/
   
#include <LiquidCrystal.h>
   
/*************************************************************************************************************
*******************************CLASSE LCD BIG NUMBERS*********************************************************
**************************************************************************************************************/
struct LCDNumber {
  byte top1;
  byte top2;
  byte top3;
  byte bottom1;
  byte bottom2;
  byte bottom3;
};
 
class LCDBigNumbers {
  private:
    LiquidCrystal * _lcd;
    int _row;
    int _col;
    long _value; /*0..100*/
     
    void _clear(){
      int cont = 1;
      long x = 9;
      while (_value > x){
        cont++;
        x = x * 10 + 9;
      }
      for (int i=0; i<cont; i++) {
        _lcd->setCursor(_col+i, _row);
        _lcd->print( "    " );
        _lcd->setCursor(_col+i, _row+1);
        _lcd->print( "    " );
      }
    }
  public:
    static byte c0[8];  //bottom
    static byte c1[8];  //top
    static byte c2[8];  //fill
    static byte c3[8];
    static byte c4[8];
    static byte c5[8];  //top-bottom 
    static LCDNumber _lcd_numbers[];
    
    void createChars() {
      _lcd->createChar(0, c0);
      _lcd->createChar(1, c1);
      _lcd->createChar(2, c2);
      _lcd->createChar(3, c3);
      _lcd->createChar(4, c4);
      _lcd->createChar(5, c5);
      //_lcd->createChar(6, c6);
      //_lcd->createChar(7, c7);
    }
     
    LCDBigNumbers(LiquidCrystal * lcd, int row, int col) {
      _lcd = lcd;      _row = row;      _col = col;
    }
     
    void setRow(int row){
      _clear();
      _row = row;
      setValue(_value);
    }
    void setCol(int col){
      _clear();
      _col = col;
      setValue(_value);
    }
     
    void setValue(long value){
      _clear();
      _value = value;
       
      int cont = 1;
      long x = 9;
      while (abs(_value) > x){
        cont++;
        x = x * 10 + 9;
      }
       
      for (int i=0; i<cont; i++) {
        int n = value / pow(10, cont-1-i);
        value = value - pow(10, cont-1-i) * n;
         
        _lcd->setCursor(_col+i*4, _row);
        _lcd_numbers[n].top1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top1 );
        _lcd_numbers[n].top2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top2 );
        _lcd_numbers[n].top3 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top3 );
        _lcd->setCursor(_col+i*4, _row+1);
        _lcd_numbers[n].bottom1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom1 );
        _lcd_numbers[n].bottom2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom2 );
        _lcd_numbers[n].bottom3 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom3 );
      }
    }
};

byte LCDBigNumbers::c0[8] = {B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111};  //bottom
byte LCDBigNumbers::c1[8] = {B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000};  //top
byte LCDBigNumbers::c2[8] = {B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111};  //fill
byte LCDBigNumbers::c3[8] = {B00000, B00000, B00001, B00011, B00011, B00001, B00000, B00000};
byte LCDBigNumbers::c4[8] = {B00000, B00000, B10000, B11000, B11000, B10000, B00000, B00000};
byte LCDBigNumbers::c5[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B11111, B11111};   //top / bottom 

LCDNumber LCDBigNumbers::_lcd_numbers[] = { 
      {2, 1, 2, 2, 0, 2}, //0
      {1, 2, 9, 0, 2, 0}, //1
      {1, 5, 2, 2, 0, 0}, //2
      {1, 5, 2, 0, 0, 2}, //3
      {2, 0, 2, 9, 9, 2}, //4
      {2, 5, 1, 0, 0, 2}, //5
      {2, 5, 1, 2, 0, 2}, //6
      {1, 1, 2, 9, 9, 2}, //7
      {2, 5, 2, 2, 0, 2}, //8
      {2, 5, 2, 0, 0, 2} // 9
    };
/*************************************************************************************************************
*******************************FIM CLASSE LCD BIG NUMBERS*****************************************************
**************************************************************************************************************/
   
   
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LCDBigNumbers lcdNum(&lcd, 0,0); //inclui uma barra no lcd, primeira linha, coluna 1
   
void setup()   {
  Serial.begin(9600);
  lcdNum.createChars();
  lcdNum.setCol(1); //muda para a coluna 1
  
  pinMode(44, OUTPUT);  //arduino mega - pino de contraste do display
  analogWrite(44, 255/6); //utilizado para aumentar o contraste
  lcd.begin(16, 2);
}
 
long i = 0;
int col = 0;
 
void loop() {
  lcdNum.setValue(i++ * 11);
   
  if (i>=10000) { i = 0; }

  delay(500);  
}


Código terceira e quarta versão:

obs. para inverter entre a terceira e quarta versão verificar o código comentado onde os caracteres customizados são definidos.

/*
Fabiano A. Arndt - 2015
www.youtube.com/user/fabianoallex
www.facebook.com/dicasarduino
fabianoallex@gmail.com
*/
   
#include <LiquidCrystal.h>
   
/*************************************************************************************************************
*******************************CLASSE LCD BIG NUMBERS*********************************************************
**************************************************************************************************************/
struct LCDNumber {
  byte top1;
  byte top2;
  byte bottom1;
  byte bottom2;
};
 
class LCDBigNumbers {
  private:
    LiquidCrystal * _lcd;
    int _row;
    int _col;
    long _value; /*0..100*/
    byte _dist;  /*distancia entre digitos*/
     
    void _clear(){
      int cont = 1;
      long x = 9;
      while (_value > x){
        cont++;
        x = x * 10 + 9;
      }
      for (int i=0; i<cont; i++) {
        _lcd->setCursor(_col+i, _row);
        _lcd->print( "  " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
        _lcd->setCursor(_col+i, _row+1);
        _lcd->print( "  " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
      }
    }
  public:
    static byte c0[8];  
    static byte c1[8];  
    static byte c2[8];  
    static byte c3[8];
    static byte c4[8];
    static byte c5[8];  
    static byte c6[8];  
    static byte c7[8];  
    static LCDNumber _lcd_numbers[];
    
    void createChars() {
      _lcd->createChar(0, c0);
      _lcd->createChar(1, c1);
      _lcd->createChar(2, c2);
      _lcd->createChar(3, c3);
      _lcd->createChar(4, c4);
      _lcd->createChar(5, c5);
      _lcd->createChar(6, c6);
      _lcd->createChar(7, c7);
    }
     
    LCDBigNumbers(LiquidCrystal * lcd, int row, int col) {
      _lcd = lcd;      
      _row = row;      
      _col = col;
      _dist = 0;  //distancia entre os numeros
    }
     
    void setRow(int row){
      _clear();
      _row = row;
      setValue(_value);
    }
    void setCol(int col){
      _clear();
      _col = col;
      setValue(_value);
    }
    
    void setDist(int dist){
      _clear();
      _dist = dist;
      setValue(_value);
    }
     
    void setValue(long value){
      _clear();
      _value = value;
       
      int cont = 1;
      long x = 9;
      while (abs(_value) > x){
        cont++;
        x = x * 10 + 9;
      }
       
      for (int i=0; i<cont; i++) {
        int n = value / pow(10, cont-1-i);
        value = value - pow(10, cont-1-i) * n;
         
        _lcd->setCursor(_col+i*(2+_dist), _row);
        _lcd_numbers[n].top1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top1 );
        _lcd_numbers[n].top2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top2 );
        _lcd->setCursor(_col+i*(2+_dist), _row+1);
        _lcd_numbers[n].bottom1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom1 );
        _lcd_numbers[n].bottom2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom2 );
      }
    }
};

//byte LCDBigNumbers::c0[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11000, B11000}; 
//byte LCDBigNumbers::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigNumbers::c2[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B00011, B00011};  
//byte LCDBigNumbers::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B11111, B11111};
//byte LCDBigNumbers::c4[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigNumbers::c5[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B11111, B11111};  
//byte LCDBigNumbers::c6[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigNumbers::c7[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B11111, B11111};  

byte LCDBigNumbers::c0[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11000}; 
byte LCDBigNumbers::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
byte LCDBigNumbers::c2[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B00011};  
byte LCDBigNumbers::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B00011, B11111};
byte LCDBigNumbers::c4[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
byte LCDBigNumbers::c5[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B11111};  
byte LCDBigNumbers::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
byte LCDBigNumbers::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 

//byte LCDBigNumbers::c0[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B10000}; 
//byte LCDBigNumbers::c1[8] = {B10000, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
//byte LCDBigNumbers::c2[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B00001};  
//byte LCDBigNumbers::c3[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B11111};
//byte LCDBigNumbers::c4[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
//byte LCDBigNumbers::c5[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111};  
//byte LCDBigNumbers::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigNumbers::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 

LCDNumber LCDBigNumbers::_lcd_numbers[] = { 
      {0, 2, 1, 3}, //0
      {2, 9, 3, 1}, //1
      {7, 5, 4, 7}, //2
      {7, 5, 7, 5}, //3
      {1, 3, 6, 2}, //4
      {4, 7, 7, 5}, //5
      {4, 7, 4, 5}, //6
      {6, 5, 9, 2}, //7
      {4, 5, 4, 5}, //8
      {4, 5, 7, 5} // 9
    };
/*************************************************************************************************************
*******************************FIM CLASSE LCD BIG NUMBERS*****************************************************
**************************************************************************************************************/
   
   
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LCDBigNumbers lcdNum(&lcd, 0,0); //inclui uma barra no lcd, primeira linha, coluna 1
   
void setup()   {
  Serial.begin(9600);
  lcdNum.createChars(); //cria os caracteres especiais na memoria
  lcdNum.setCol(1); //muda para a coluna numero 1
  lcdNum.setDist(1); //1 coluna entre um numero e outro
  
  
  pinMode(44, OUTPUT);  //arduino mega - pino de contraste do display
  analogWrite(44, 255/6); //utilizado para aumentar o contraste
  lcd.begin(16, 2);
}
 
long i = 0;
int col = 0;
 
void loop() {
  lcdNum.setValue(i++ * 11);
   
  if (i>=10000) { i = 0; }

  delay(500);  
}



O Código abaixo é uma versão alterada pra mostrar números e letras, a qual não está no vídeo. Ainda precisa de umas melhorias, mas de qualquer maneira, deixo aqui pra quem quiser testar:



/*
Fabiano A. Arndt - 2015
www.youtube.com/user/fabianoallex
www.facebook.com/dicasarduino
fabianoallex@gmail.com
*/
   
#include <LiquidCrystal.h>
   
/*************************************************************************************************************
*******************************CLASSE LCD BIG TEXT*********************************************************
**************************************************************************************************************/
struct LCDChar {
  byte top1;
  byte top2;
  byte bottom1;
  byte bottom2;
};
 
class LCDBigText {
  private:
    LiquidCrystal * _lcd;
    int _row;
    int _col;
    String _value; /*0..100*/
    byte _dist;  /*distancia entre digitos*/
     
    void _clear(){
      
      for (int i=0; i<_value.length(); i++) {
        //_lcd->setCursor(_col+i, _row);
        _lcd->setCursor(_col+i*(2+_dist), _row);
        _lcd->print( " " );
        _lcd->print( " " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
        _lcd->setCursor(_col+i*(2+_dist), _row+1);
        //_lcd->setCursor(_col+i, _row+1);
        _lcd->print( " " );
        _lcd->print( " " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
      }
    }
  public:
    static byte c0[8];  
    static byte c1[8];  
    static byte c2[8];  
    static byte c3[8];
    static byte c4[8];
    static byte c5[8];  
    static byte c6[8];  
    static byte c7[8];  
    static LCDChar _lcd_chars[];
    
    void createChars() {
      _lcd->createChar(0, c0);
      _lcd->createChar(1, c1);
      _lcd->createChar(2, c2);
      _lcd->createChar(3, c3);
      _lcd->createChar(4, c4);
      _lcd->createChar(5, c5);
      _lcd->createChar(6, c6);
      _lcd->createChar(7, c7);
    }
     
    LCDBigText(LiquidCrystal * lcd, int row, int col) {
      _lcd = lcd;      
      _row = row;      
      _col = col;
      _dist = 0;  //distancia entre os numeros
    }
     
    void setRow(int row){
      _clear();
      _row = row;
      setValue(_value);
    }
    void setCol(int col){
      _clear();
      _col = col;
      setValue(_value);
    }
    
    void setDist(int dist){
      _clear();
      _dist = dist;
      setValue(_value);
    }
     
    void setValue(String value){
      _clear();
      _value = value;
             
      for (int i=0; i<_value.length(); i++) {
        char n = value[i];
        
        //tabela ascii
        if (n >= 97 && n<=122){
          n = n - 97 + 10;
        } else if (n >= 65 && n<=90){
          n = n - 65 + 10;
        } else if (n >= 48 && n<=57) {
          n = n - 48;
        } else {
          n = 36;  //space
        }
        
        if (n ==0 ){
          _lcd->setCursor(_col+i*(2+_dist), _row);
          _lcd->print("  ");
          _lcd->setCursor(_col+i*(2+_dist), _row+1);
          _lcd->print("  ");
        } else {
          _lcd->setCursor(_col+i*(2+_dist), _row);
          _lcd_chars[n].top1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_chars[n].top1 );
          _lcd_chars[n].top2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_chars[n].top2 );
          _lcd->setCursor(_col+i*(2+_dist), _row+1);
          _lcd_chars[n].bottom1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_chars[n].bottom1 );
          _lcd_chars[n].bottom2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_chars[n].bottom2 );
        }
      }
    }
};

//byte LCDBigText::c0[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11000, B11000}; 
//byte LCDBigText::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigText::c2[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B00011, B00011};  
//byte LCDBigText::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B11111, B11111};
//byte LCDBigText::c4[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigText::c5[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B11111, B11111};  
//byte LCDBigText::c6[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigText::c7[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B11111, B11111};  

//byte LCDBigText::c0[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11000}; 
//byte LCDBigText::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
//byte LCDBigText::c2[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B00011};  
//byte LCDBigText::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B00011, B11111};
//byte LCDBigText::c4[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
//byte LCDBigText::c5[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B11111};  
//byte LCDBigText::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigText::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 

byte LCDBigText::c0[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B10000}; 
byte LCDBigText::c1[8] = {B10000, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
byte LCDBigText::c2[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B00001};  
byte LCDBigText::c3[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B11111};
byte LCDBigText::c4[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
byte LCDBigText::c5[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111};  
byte LCDBigText::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
byte LCDBigText::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 

LCDChar LCDBigText::_lcd_chars[] = { 
      {0, 2, 1, 3}, //0
      {2, 9, 3, 1}, //1
      {7, 5, 4, 7}, //2
      {7, 5, 7, 5}, //3
      {1, 3, 6, 2}, //4
      {4, 7, 7, 5}, //5
      {4, 7, 4, 5}, //6
      {6, 5, 9, 2}, //7
      {4, 5, 4, 5}, //8
      {4, 5, 7, 5}, //9
      {0, 2, 0, 2}, //a
      {1, 9, 4, 5}, //b
      {0, 6, 1, 95}, //c
      {9, 3, 4, 5}, //d
      {4, 7, 4, 7}, //e
      {4, 6, 0, 9}, //f
      {0, 7, 1, 5}, //g
      {1, 3, 0, 2}, //h
      {3, 9, 3, 1}, //i
      {9, 2, 1, 3}, //j
      {1, '/', 0, '\\'}, //k
      {2, 9, 3, 1}, //l
      {95, 95, 0, 2}, //m
      {95, 9, 0, 2}, //n
      {0, 2, 1, 3}, //o
      {4, 5, 0, 6}, //p
      {4, 5, 6, 2}, //q
      {4, 5, 0, '\\'}, //r
      {4, 7, 7, 5}, //s
      {3, 1, 5, 4}, //t
      {9, 9, 1, 3}, //u
      {1, 3, '\\', '/'}, //v
      {1, 3, 'w', 'w'}, //w
      {'\\', '/', '/', '\\'}, //x
      {1, 3, 6, 2}, //y
      {6, '/', '/', 95}, //z
      {9, 9, 9, 9} //' '
    };
/*************************************************************************************************************
*******************************FIM CLASSE LCD BIG TEXT*****************************************************
**************************************************************************************************************/
   
   
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LCDBigText lcdText(&lcd, 0,0); //inclui uma barra no lcd, primeira linha, coluna 1
   
void setup()   {
  Serial.begin(9600);
  lcdText.createChars(); //cria os caracteres especiais na memoria
  lcdText.setCol(0); //muda para a coluna numero 1
  lcdText.setDist(1); //1 coluna entre um numero e outro
  
  
  pinMode(44, OUTPUT);  //arduino mega - pino de contraste do display
  analogWrite(44, 255/6); //utilizado para aumentar o contraste
  lcd.begin(16, 2);
  
}
 
long i = 0;
int col = 0;
 
void loop() {
  
  lcd.clear();
  
  lcdText.setValue("ARDUINO");
  delay(3000);
  
  for (int i = 0; i < 20; i++) {
    lcd.scrollDisplayLeft();
    delay(600);
  }
  
  lcd.clear();
  
  lcdText.setValue("01234");
  delay(3000);
  
  lcdText.setValue("56789");
  delay(3000);
   
  lcdText.setValue("abcde");
  delay(3000);

  lcdText.setValue("fghij");
  delay(3000);  
  
  lcdText.setValue("klmno");
  delay(3000);
  
  lcdText.setValue("pqrst");
  delay(3000);
  
  lcdText.setValue("uvx");
  delay(3000);
  
  lcdText.setValue("wyz");
  delay(3000);
    
  lcdText.setValue("ABCDE");
  delay(3000);

  lcdText.setValue("FGHIJ");
  delay(3000);  
  
  lcdText.setValue("KLMNO");
  delay(3000);
  
  lcdText.setValue("PQRST");
  delay(3000);
  
  lcdText.setValue("UVX");
  delay(3000);
  
  lcdText.setValue("WYZ");
  delay(3000);
  
  
}

Nesse outro exemplo, é mostrado como juntar mais de um formato em uma mesma sketch. Por padrão o LCD aceita apenas 8 caracteres customizáveis, mas é possível criar mais de oito, desde que se tenha apenas 8 sendo usado por vez. Ao terminar de usar os primeiros 8, pode-se definir os outros 8 caracteres customizáveis.




/*
Fabiano A. Arndt - 2015
www.youtube.com/user/fabianoallex
www.facebook.com/dicasarduino
fabianoallex@gmail.com
*/
    
#include <LiquidCrystal.h>
    
/*************************************************************************************************************
*******************************CLASSE LCD BIG NUMBERS 1*******************************************************
**************************************************************************************************************/
struct LCDNumber_1 {
  byte top;
  byte bottom;
};
  
class LCDBigNumbers_1 {
  private:
    LiquidCrystal * _lcd;
    int _row;
    int _col;
    long _value; /*0..100*/
      
    void _clear(){
      int cont = 1;
      long x = 9;
      while (_value > x){
        cont++;
        x = x * 10 + 9;
      }
      for (int i=0; i<cont; i++) {
        _lcd->setCursor(_col+i, _row);
        _lcd->print( " " );
        _lcd->setCursor(_col+i, _row+1);
        _lcd->print( " " );
      }
    }
  public:
    static byte c0[8];  
    static byte c1[8];  
    static byte c2[8];  
    static byte c3[8];
    static byte c4[8];
    static byte c5[8];  
    static byte c6[8];  
    static byte c7[8];  
    static LCDNumber_1 _lcd_numbers[];
     
    void createChars() {
      _lcd->createChar(0, c0);
      _lcd->createChar(1, c1);
      _lcd->createChar(2, c2);
      _lcd->createChar(3, c3);
      _lcd->createChar(4, c4);
      _lcd->createChar(5, c5);
      _lcd->createChar(6, c6);
      _lcd->createChar(7, c7);
    }
      
    LCDBigNumbers_1(LiquidCrystal * lcd, int row, int col) {
      _lcd = lcd;      _row = row;      _col = col;
    }
      
    void setRow(int row){
      _clear();
      _row = row;
      setValue(_value);
    }
    void setCol(int col){
      _clear();
      _col = col;
      setValue(_value);
    }
      
    void setValue(long value){
      _clear();
      _value = value;
        
      int cont = 1;
      long x = 9;
      while (abs(_value) > x){
        cont++;
        x = x * 10 + 9;
      }
        
      for (int i=0; i<cont; i++) {
        int n = value / pow(10, cont-1-i);
        value = value - pow(10, cont-1-i) * n;
          
        _lcd->setCursor(_col+i, _row);
        _lcd->write( _lcd_numbers[n].top );
        _lcd->setCursor(_col+i, _row+1);
        _lcd->write( _lcd_numbers[n].bottom );
      }
        
    }
};
 
byte LCDBigNumbers_1::c0[8] = {B11111, B10001, B10001, B10001, B10001, B10001, B10001, B10001};
byte LCDBigNumbers_1::c1[8] = {B10001, B10001, B10001, B10001, B10001, B10001, B10001, B11111};
byte LCDBigNumbers_1::c2[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B00001};
byte LCDBigNumbers_1::c3[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111};
byte LCDBigNumbers_1::c4[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111};
byte LCDBigNumbers_1::c5[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B00001};    
byte LCDBigNumbers_1::c6[8] = {B11111, B10001, B10001, B10001, B10001, B10001, B10001, B11111};              
byte LCDBigNumbers_1::c7[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B11111};
 
 
LCDNumber_1 LCDBigNumbers_1::_lcd_numbers[] = { 
  {0, 1}, //0
  {2, 2}, //1
  {5, 4}, //2
  {3, 7}, //3
  {1, 2}, //4
  {4, 7}, //5
  {4, 1}, //6
  {5, 2}, //7
  {6, 1}, //8
  {6, 7} // 9
};
  
 
/*************************************************************************************************************
*******************************FIM CLASSE LCD BIG NUMBERS 1***************************************************
**************************************************************************************************************/
    
    
/*************************************************************************************************************
*******************************CLASSE LCD BIG NUMBERS 2*******************************************************
**************************************************************************************************************/
struct LCDNumber_2 {
  byte top1;
  byte top2;
  byte bottom1;
  byte bottom2;
};
  
class LCDBigNumbers_2 {
  private:
    LiquidCrystal * _lcd;
    int _row;
    int _col;
    long _value; /*0..100*/
    byte _dist;  /*distancia entre digitos*/
      
    void _clear(){
      int cont = 1;
      long x = 9;
      while (_value > x){
        cont++;
        x = x * 10 + 9;
      }
      for (int i=0; i<cont; i++) {
        _lcd->setCursor(_col+i, _row);
        _lcd->print( "  " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
        _lcd->setCursor(_col+i, _row+1);
        _lcd->print( "  " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
      }
    }
  public:
    static byte c0[8];  
    static byte c1[8];  
    static byte c2[8];  
    static byte c3[8];
    static byte c4[8];
    static byte c5[8];  
    static byte c6[8];  
    static byte c7[8];  
    static LCDNumber_2 _lcd_numbers[];
     
    void createChars() {
      _lcd->createChar(0, c0);
      _lcd->createChar(1, c1);
      _lcd->createChar(2, c2);
      _lcd->createChar(3, c3);
      _lcd->createChar(4, c4);
      _lcd->createChar(5, c5);
      _lcd->createChar(6, c6);
      _lcd->createChar(7, c7);
    }
      
    LCDBigNumbers_2(LiquidCrystal * lcd, int row, int col) {
      _lcd = lcd;      
      _row = row;      
      _col = col;
      _dist = 0;  //distancia entre os numeros
    }
      
    void setRow(int row){
      _clear();
      _row = row;
      setValue(_value);
    }
    void setCol(int col){
      _clear();
      _col = col;
      setValue(_value);
    }
     
    void setDist(int dist){
      _clear();
      _dist = dist;
      setValue(_value);
    }
      
    void setValue(long value){
      _clear();
      _value = value;
        
      int cont = 1;
      long x = 9;
      while (abs(_value) > x){
        cont++;
        x = x * 10 + 9;
      }
        
      for (int i=0; i<cont; i++) {
        int n = value / pow(10, cont-1-i);
        value = value - pow(10, cont-1-i) * n;
          
        _lcd->setCursor(_col+i*(2+_dist), _row);
        _lcd_numbers[n].top1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top1 );
        _lcd_numbers[n].top2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top2 );
        _lcd->setCursor(_col+i*(2+_dist), _row+1);
        _lcd_numbers[n].bottom1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom1 );
        _lcd_numbers[n].bottom2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom2 );
      }
    }
};
 
//byte LCDBigNumbers_2::c0[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11000, B11000}; 
//byte LCDBigNumbers_2::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigNumbers_2::c2[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B00011, B00011};  
//byte LCDBigNumbers_2::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B11111, B11111};
//byte LCDBigNumbers_2::c4[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigNumbers_2::c5[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B11111, B11111};  
//byte LCDBigNumbers_2::c6[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigNumbers_2::c7[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B11111, B11111};  
 
byte LCDBigNumbers_2::c0[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11000}; 
byte LCDBigNumbers_2::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
byte LCDBigNumbers_2::c2[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B00011};  
byte LCDBigNumbers_2::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B00011, B11111};
byte LCDBigNumbers_2::c4[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
byte LCDBigNumbers_2::c5[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B11111};  
byte LCDBigNumbers_2::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
byte LCDBigNumbers_2::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 
 
//byte LCDBigNumbers_2::c0[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B10000}; 
//byte LCDBigNumbers_2::c1[8] = {B10000, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
//byte LCDBigNumbers_2::c2[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B00001};  
//byte LCDBigNumbers_2::c3[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B11111};
//byte LCDBigNumbers_2::c4[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
//byte LCDBigNumbers_2::c5[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111};  
//byte LCDBigNumbers_2::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigNumbers_2::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 
 
LCDNumber_2 LCDBigNumbers_2::_lcd_numbers[] = { 
      {0, 2, 1, 3}, //0
      {2, 9, 3, 1}, //1
      {7, 5, 4, 7}, //2
      {7, 5, 7, 5}, //3
      {1, 3, 6, 2}, //4
      {4, 7, 7, 5}, //5
      {4, 7, 4, 5}, //6
      {6, 5, 9, 2}, //7
      {4, 5, 4, 5}, //8
      {4, 5, 7, 5} // 9
    };
/*************************************************************************************************************
*******************************FIM CLASSE LCD BIG NUMBERS 2***************************************************
**************************************************************************************************************/
 
    
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LCDBigNumbers_1 lcdNum_1(&lcd, 0,0); //inclui uma barra no lcd, primeira linha, coluna 1
LCDBigNumbers_2 lcdNum_2(&lcd, 0,0); //inclui uma barra no lcd, primeira linha, coluna 1
    
void setup()   {
  Serial.begin(9600);
  lcdNum_1.createChars(); //cria os caracteres especiais na memoria
  lcdNum_2.setDist(1);
   
  pinMode(44, OUTPUT);  //arduino mega - pino de contraste do display
  analogWrite(44, 255/6); //utilizado para aumentar o contraste
  lcd.begin(16, 2);
}
  
long i = 0;
int col = 0;
  
int x = 1;
  
void loop() {
  int c = Serial.read();
    
  if (c == 97)  { lcd.clear(); lcdNum_1.createChars(); x = 1;  } //a
  if (c == 98)  { lcd.clear(); lcdNum_2.createChars(); x = 2;  } //b
   
  if (x == 1) { lcdNum_1.setValue(i++ * 11); }
  if (x == 2) { lcdNum_2.setValue(i++ * 11); }
  
  if (i>=10000) { i = 0; }
  delay(500);  
}



Pra demonstrar com um exemplo um pouco mais prático, criei um relógio que mostra a data e hora em um display LCD, utilizando RTC - DS3231




Código-fonte:

 /*
Fabiano A. Arndt - 2015
www.youtube.com/user/fabianoallex
www.facebook.com/dicasarduino
fabianoallex@gmail.com
*/
    
#include <LiquidCrystal.h>
#include <Wire.h>
#include "DS3231.h"


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
DS3231 RTC; 
    
/*************************************************************************************************************
*******************************CLASSE LCD BIG NUMBERS*********************************************************
para mais detalhes: http://fabianoallex.blogspot.com.br/2015/10/arduino-lcd-big-numbers.html
**************************************************************************************************************
**************************************************************************************************************/
struct LCDNumber {
  byte top1;
  byte top2;
  byte bottom1;
  byte bottom2;
};
  
class LCDBigNumbers {
  private:
    LiquidCrystal * _lcd;
    int _row;
    int _col;
    long _value; /*0..100*/
    byte _dist;  /*distancia entre digitos*/
    byte _min_size; /*tamanho minimo.  3--> 001   002 ;;;;  2 --> 01   02*/
      
    void _clear(){
      int cont = 1;
      long x = 9;
      while (_value > x){
        cont++;
        x = x * 10 + 9;
      }
      
      for (int i=0; i<cont; i++) {
        if (cont <= (_min_size-1) && i <= (_min_size -2) ){ //zeros a esquerda
          cont ++;
        }
        
        _lcd->setCursor(_col+i*(2+_dist), _row);
        _lcd->print( " " );
        _lcd->print( " " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
        _lcd->setCursor(_col+i*(2+_dist), _row+1);
        _lcd->print( " " );
        _lcd->print( " " );
        for (byte b=0;b<_dist; b++){ _lcd->print( " " ); }
      }
    }
  public:
    static byte c0[8];  
    static byte c1[8];  
    static byte c2[8];  
    static byte c3[8];
    static byte c4[8];
    static byte c5[8];  
    static byte c6[8];  
    static byte c7[8];  
    static LCDNumber _lcd_numbers[];
     
    void createChars() {
      _lcd->createChar(0, c0);
      _lcd->createChar(1, c1);
      _lcd->createChar(2, c2);
      _lcd->createChar(3, c3);
      _lcd->createChar(4, c4);
      _lcd->createChar(5, c5);
      _lcd->createChar(6, c6);
      _lcd->createChar(7, c7);
    }
      
    LCDBigNumbers(LiquidCrystal * lcd, int row, int col) {
      _lcd = lcd;      
      _row = row;      
      _col = col;
      _dist = 0;  //distancia entre os numeros
      _min_size = 1;
    }
      
    void setRow(int row){
      _clear();
      _row = row;
      setValue(_value);
    }
    void setCol(int col){
      _clear();
      _col = col;
      setValue(_value);
    }
     
    void setDist(int dist){
      _clear();
      _dist = dist;
      setValue(_value);
    }
    
    void setMinSize(byte min_size){
      _min_size = min_size;
    }
      
    void setValue(long value){
      _clear();
      _value = value;
        
      int cont = 1;
      long x = 9;
      while (abs(_value) > x){
        cont++;
        x = x * 10 + 9;
      }
      
      for (int i=0; i<cont; i++) {
        int n;
        
        if (cont <= (_min_size-1) && i <= (_min_size -2) ){ //zeros a esquerda
          n = 0;
          cont ++;
        } else {
          
          n = value / pow(10, cont-1-i);
          value = value - pow(10, cont-1-i) * n;
        }
          
        _lcd->setCursor(_col+i*(2+_dist), _row);
        _lcd_numbers[n].top1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top1 );
        _lcd_numbers[n].top2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].top2 );
        _lcd->setCursor(_col+i*(2+_dist), _row+1);
        _lcd_numbers[n].bottom1 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom1 );
        _lcd_numbers[n].bottom2 == 9 ? _lcd->print(" ") : _lcd->write( _lcd_numbers[n].bottom2 );
      }
    }
};
 
//byte LCDBigNumbers::c0[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11000, B11000}; 
//byte LCDBigNumbers::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigNumbers::c2[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B00011, B00011};  
//byte LCDBigNumbers::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B11111, B11111};
//byte LCDBigNumbers::c4[8] = {B11111, B11111, B11000, B11000, B11000, B11000, B11111, B11111};  
//byte LCDBigNumbers::c5[8] = {B11111, B11111, B00011, B00011, B00011, B00011, B11111, B11111};  
//byte LCDBigNumbers::c6[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigNumbers::c7[8] = {B11111, B11111, B00000, B00000, B00000, B00000, B11111, B11111};  
 
byte LCDBigNumbers::c0[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11000}; 
byte LCDBigNumbers::c1[8] = {B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
byte LCDBigNumbers::c2[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B00011};  
byte LCDBigNumbers::c3[8] = {B00011, B00011, B00011, B00011, B00011, B00011, B00011, B11111};
byte LCDBigNumbers::c4[8] = {B11111, B11000, B11000, B11000, B11000, B11000, B11000, B11111};  
byte LCDBigNumbers::c5[8] = {B11111, B00011, B00011, B00011, B00011, B00011, B00011, B11111};  
byte LCDBigNumbers::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
byte LCDBigNumbers::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 
 
//byte LCDBigNumbers::c0[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B10000}; 
//byte LCDBigNumbers::c1[8] = {B10000, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
//byte LCDBigNumbers::c2[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B00001};  
//byte LCDBigNumbers::c3[8] = {B00001, B00001, B00001, B00001, B00001, B00001, B00001, B11111};
//byte LCDBigNumbers::c4[8] = {B11111, B10000, B10000, B10000, B10000, B10000, B10000, B11111};  
//byte LCDBigNumbers::c5[8] = {B11111, B00001, B00001, B00001, B00001, B00001, B00001, B11111};  
//byte LCDBigNumbers::c6[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B00000};  
//byte LCDBigNumbers::c7[8] = {B11111, B00000, B00000, B00000, B00000, B00000, B00000, B11111}; 
 
LCDNumber LCDBigNumbers::_lcd_numbers[] = { 
      {0, 2, 1, 3}, //0
      {2, 9, 3, 1}, //1
      {7, 5, 4, 7}, //2
      {7, 5, 7, 5}, //3
      {1, 3, 6, 2}, //4
      {4, 7, 7, 5}, //5
      {4, 7, 4, 5}, //6
      {6, 5, 9, 2}, //7
      {4, 5, 4, 5}, //8
      {4, 5, 7, 5} // 9
    };
/*************************************************************************************************************
*******************************FIM CLASSE LCD BIG NUMBERS*****************************************************
**************************************************************************************************************/

/*************************************************************************************************************
*******************************FUNÇÃO TIME********************************************************************
mais detalhes: http://fabianoallex.blogspot.com.br/2015/09/arduino-como-substituir-delay-pelo.html
*************************************************************************************************************
**************************************************************************************************************/
    
int time(long timeHigh, long timeLow, long atraso, long mref = 0) {
  long ajuste = mref % (timeHigh + timeLow);
  long resto  = (millis() + timeHigh + timeLow - ajuste - atraso) % (timeHigh + timeLow);
  return (resto < timeHigh ? HIGH : LOW);
}
/*************************************************************************************************************
*******************************FIM FUNÇÃO TIME****************************************************************
**************************************************************************************************************/



/*************************************************************************************************************
*******************************FUNÇÕES DO RELOGIO*************************************************************
**************************************************************************************************************/

LCDBigNumbers lcdNum01(&lcd, 0, 1); //inclui um número no lcd, primeira linha, coluna 1
LCDBigNumbers lcdNum02(&lcd, 0, 6); //inclui um número no lcd, primeira linha, coluna 6
LCDBigNumbers lcdNum03(&lcd, 0, 11); //inclui um número no lcd, primeira linha, coluna 11
    
int sec = 0;
int date = 0;
unsigned long mclock = 0;
char dot = ' ';
  
void show_clock(){
  if (millis()-mclock > 500) {
    
    DateTime now = RTC.now(); //get the current date-time
  
    if (sec != now.second()){
      lcdNum01.setValue(now.hour());
      lcdNum02.setValue(now.minute());
      lcdNum03.setValue(now.second());
      
      sec = now.second();
    }
    
    dot = (dot == '.') ? dot = ' ' : dot = '.';

    lcd.setCursor(5, 0);
    lcd.print(dot);
    lcd.setCursor(10, 0);
    lcd.print(dot);
    lcd.setCursor(5, 1);
    lcd.print(dot);
    lcd.setCursor(10, 1);
    lcd.print(dot);
    
    mclock = millis();
  }
}


void show_date(){
  if (millis()-mclock > 500) {
    DateTime now = RTC.now(); //get the current date-time
    
    if (date != now.second()){
      lcdNum01.setValue(now.date());
      lcdNum02.setValue(now.month());
      lcdNum03.setValue(now.year()-2000);
      
      date = now.date();
    }
    
    lcd.setCursor(5, 0);
    lcd.print(' ');
    lcd.setCursor(10, 0);
    lcd.print(' ');
    
    lcd.setCursor(5, 1);
    lcd.print('.');
    lcd.setCursor(10, 1);
    lcd.print('.');
    
    mclock = millis();
  }
}

/*************************************************************************************************************
*******************************FIM FUNÇÕES DO RELOGIO*********************************************************
**************************************************************************************************************/

void setup()   {
  Serial.begin(9600);
  lcdNum01.createChars(); //cria os caracteres especiais na memoria
  
  lcdNum01.setMinSize(2); //duas casas 00 01 02
  lcdNum02.setMinSize(2); //duas casas 00 01 02
  lcdNum03.setMinSize(2); //duas casas 00 01 02
   
  pinMode(44, OUTPUT);  //arduino mega - pino de contraste do display
  analogWrite(44, 255/6); //utilizado para aumentar o contraste
  lcd.begin(16, 2);
  
  Wire.begin();
  RTC.begin();
}

void loop() {
  //mostra por 10 segundos a hora e por 5 segundos a data
  if ( time(10000, 5000, 0) ) {
    show_clock();
  } else {
    show_date();
  }
}


16 comentários:

  1. Muito bacana o trabalho que está fazendo, parabéns!

    ResponderExcluir
  2. Saudações Fabiano! Parabéns pelo projeto e, obrigado por disponibiliza-los.
    Deixo-lhe uma sugestão particular: desenvolver um projeto de relógio e/ou rolagem de texto com vários displays de matriz de Led bicolor (vermelho e verde).
    Obs.: É um pedido meu pois, tenho pouquíssimo conhecimento no assunto;
    Obrigado e um Feliz Natal a vc.

    ResponderExcluir
  3. Muito bom,parabens, uma duvida. usando o seu ultimo exemplo do relogio, dá erro dizendo "no matching function for call to 'DS3231::DS3231()'" e fica referenciado em DS3231 RTC; ????

    ResponderExcluir
  4. Alo, brigado pela ajuda, o que fiz foi reinstalar a biblioteca e resolveu, agora dá outro erro

    'class DS3231' has no member named 'now' , que poderá ser agora?? Mais uma vez obrigado.

    ResponderExcluir
  5. Deixo aqui o log

    C:\Users\Oficina\Documents\Arduino\teste16x2\teste16x2.ino: In function 'void show_clock()':

    teste16x2:214: error: 'class DS3231' has no member named 'now'

    DateTime now = RTC.now(); //get the current date-time

    ^

    C:\Users\Oficina\Documents\Arduino\teste16x2\teste16x2.ino: In function 'void show_date()':

    teste16x2:242: error: 'class DS3231' has no member named 'now'

    DateTime now = RTC.now(); //get the current date-time

    ^

    teste16x2:245: error: 'class DateTime' has no member named 'date'

    lcdNum01.setValue(now.date());

    ^

    teste16x2:249: error: 'class DateTime' has no member named 'date'

    date = now.date();

    ^

    C:\Users\Oficina\Documents\Arduino\teste16x2\teste16x2.ino: In function 'void setup()':

    teste16x2:283: error: 'class DS3231' has no member named 'begin'

    RTC.begin();

    ^

    Foram encontradas múltiplas bibliotecas para «LiquidCrystal.h»
    Utilizado: C:\Users\Oficina\Desktop\arduino-1.8.0\libraries\LiquidCrystal
    Não utilizado: C:\Users\Oficina\Documents\Arduino\libraries\NewliquidCrystal
    exit status 1
    'class DS3231' has no member named 'now'

    ResponderExcluir
  6. Respostas
    1. Se não me engano tem algumas bibliotecas diversas chamadas DS3231, e elas são diferentes entre si. Eu não lembro exatamente qual utilizei na época, mas ela tinha esse método chamado Now(). Nesse link aqui tem uma biblioteca que acho que é mais proximo ao que utilizei na época.

      https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout/arduino-usage

      Excluir
  7. Oi Fabiano, muito obrigado pela informaçao mas já estou completamente perdido, nao acho a biblioteca certa, ja testei umas quantas e continua dando erro no mesmo sitio mencionando o comando Now(), será que tem ai alguma nota ou alguma copia do que voce usou naquela altura?? meu deus, já nao sei o que fazer mais, apenas necessito de um relogio com numeros grandes usando quer o ds1302,ds1307 ou o ds3231 mostrando num lcd 16x2 e nao encontro nada.......

    ResponderExcluir
    Respostas
    1. Pior que eu não tenho mais os códigos, tinha em outro pc, que já era... e eu to meio parado agora com o Arduino, não tenho nem como testar pra ver como usar com outras bibliotecas

      Excluir
  8. Ok Fabiano, brigado na mesma, deixo apenas um questao caso saiba, como posso colocar os valores de um dht11 ou dht22 em posiçao vertical ou seja em vez de por exemplo aparecer no LCD 24.00c aparecer em duas linhas e só as duas casas decimais tipo 2
    4

    Abraço.

    ResponderExcluir
  9. Nao deu certo no post, o resultado que preciso é o 2 e por baixo o 4 ou seja na vertical e só estas duas casas, nao interessa os valores a seguir à virgula. Brigado.

    ResponderExcluir
  10. Tipo este comando mas para os valores de um DHT11

    lcd.setCursor(19, 0); lcd.print(upperSec);
    lcd.setCursor(19, 1); lcd.print(underSec);

    ResponderExcluir