Skip to content

Instantly share code, notes, and snippets.

@AlexLPD
Created March 8, 2018 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexLPD/1dcccc8b122f574c20743555ce9ec603 to your computer and use it in GitHub Desktop.
Save AlexLPD/1dcccc8b122f574c20743555ce9ec603 to your computer and use it in GitHub Desktop.
3 digits display number for 20x04 display with decimal degree and signum separator
//PROGRAMA QUE IMPRIME EL SIGNO Y TEMPERATURA EN
//NUMEROS DE 3 DIGITOS EN LCD
//CREADO POR: ALEJANDRO SANTIAGO SEVILLA
//01-01-2018 VERSION DE PRUEBA. APOYADO EN:
//PROGRAMA "SEPARAR UN FLOAT EN SIGNO Y INT"
/*
HACER UNA FUNCION QUE MIDA LA LONGITUD DE LA TEMPERATURA
PARA SABER QUE CASO DE IMPRESION SE VA A UTILIZAR, Y QUE
LIMPIE LOS DIGITIOS USADOS CON UNA FUNCION FOR, PARA QUE
SE IMPRIMA CORRECTAMENTE CADA VEZ, USAR LA MISMA FUNCION
PARA IMPRIMIR LOS DIGITOS DE LA TEMPERATURA, CADA QUE LA
TEMPERATURA CAMBIE, AGREGAR A UN CONTADOR, PARA QUE LA
IMPRESION DE TEMP. CAMBIE A LO LARGO DE LA PANTALLA
IF TEMPERATURA VIEJA =! TEMP NUEVA
CAMBIO = TRUE;
LONGITUD (TEMPERATURA)
if(contador+ long temperatura < numdigitos) contador = contador //la temp no alcanza el borde derecho
if contador > numdigitos) contador = 0 // empieza borde izq
for(int a = 0; a < longitud; a++)
borraCaracter en pos A
imprime caracter nuevo en pos A
softdelay //para que se borre suavemente
*/
#define build 1
#define revision 1
// LCD
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display
// OPTION 1 - for text on line 1
byte x10[8] = {0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x07};
byte x11[8] = {0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C};
byte x12[8] = {0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F};
byte x13[8] = {0x07,0x07,0x07,0x07,0x07,0x1F,0x1F,0x1F};
byte x14[8] = {0x1C,0x1C,0x1C,0x1C,0x1C,0x1F,0x1F,0x1F};
byte x15[8] = {0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C};
byte x16[8] = {0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07};
byte x17[8] = {0x00,0x00,0x0E,0x0E,0x0E,0x00,0x00,0x00};
byte row = 0,col = 0;
float temperature = -9.0;
float temp = 0;
int a= 0;
int b= 0;
int c= 0;
int d= 0;
int n= 0; // numero
int m= 0; //fracc decimal de numero
byte contador = 0;
byte numero1 = 0; // variable de prueba
byte numero2 = 0;
//*****************************************************************************************//
// Initial Setup
//*****************************************************************************************//
void setup() {
Serial.begin(9600);
lcd.begin(20, 4); // setup LCD for 16 columns and 2 rows
lcd.setBacklight(125);
lcd.createChar(0, x10); // digit piece
lcd.createChar(1, x11); // digit piece
lcd.createChar(2, x12); // digit piece
lcd.createChar(3, x13); // digit piece
lcd.createChar(4, x14); // digit piece
lcd.createChar(5, x15); // digit piece
lcd.createChar(6, x16); // digit piece
lcd.createChar(7, x17); // digit piece (colon)
row = 1;
lcd.setCursor(0,0);
lcd.print(F(" Temperatura:"));
}
//*****************************************************************************************//
// MAIN LOOP
//*****************************************************************************************//
void loop() { // run over and over again
Serial.print("#");Serial.print(contador);
temp = temperature; //PASANDO LA TEMP A UNA VARIABLE PARA SER MODIFICA EN PROGRAMA
//revisando si es menor o mayor que cero.
if(temperature < 0.0)
{
if(n> 9) negDosDig();
else negUnDig();
// number type (sig)ab.cd
n = (int)temp*-1; // quita el negativo, pierde parte decimal
a = n/10;
b = n -(a*10);
c = 10*((( temp*-1) -n)) ; // primer decimal
d = 10*((( temp*-1) -c)) ;
Serial.print(" (-) ");
Serial.print(" Temp= "); Serial.print(temperature);
Serial.print(" A= "); Serial.print(a);
Serial.print(" B= "); Serial.print(b);
Serial.print(" C= "); Serial.print(c);
Serial.print(" D= "); Serial.println(d);
}
else
{
if(n> 9) posDosDig();
else posUnDig();
n = (int)temp; // quita el negativo, pierde parte decimal
//a = 10*( temp -a) ; // dos decimales
a = n/10;
b = n -(a*10);
c = 10*( temp -n) ; // primer decimal
d = 10*( temp -c) ;
Serial.print(" (+) ");
Serial.print(" Temp= "); Serial.print(temperature);
Serial.print(" A= "); Serial.print(a);
Serial.print(" B= "); Serial.print(b);
Serial.print(" C= "); Serial.print(c);
Serial.print(" D= "); Serial.println(d);
}
delay(1000);
temperature = temperature+0.5;
contador = contador+1;
if (contador > 40){ temperature =-15; contador =0; }
}
//DISPLAY PRINTING SUBROUTINES
void negDosDig(){
doNumber(13, row,1); //signo negativo
doNumber(a, row,3); //prier parte antes del cero
doNumber(b, row,5); //segunda parte num antes de cero
doNumber(14, row,8); //punto decimal
doNumber(c, row,9); //parte decimal
doNumber(15, row,12); //signo de centigrados
}
void negUnDig(){
doNumber(16, row,1); //borra signo negativo
doNumber(16, row,2); //borra signo negativo
doNumber(a, row,3); //prier parte antes del cero
doNumber(16, row,2); //borra signo negativo
doNumber(16, row,3); //borra signo negativo
doNumber(13, row,2); //signo negativo //
doNumber(b, row,5); //segunda parte num antes de cero
doNumber(14, row,8); //punto decimal
doNumber(c, row,9); //parte decimal
doNumber(15, row,12); //signo de centigrados
}
void posDosDig(){
doNumber(16, row,1); //borra signo negativo
doNumber(16, row,3); //borra signo negativo
doNumber(a, row,3); //prier parte antes del cero
doNumber(b, row,5); //segunda parte num antes de cero
doNumber(14, row,8); //punto decimal
doNumber(c, row,9); //parte decimal
doNumber(15, row,12); //signo de centigrados
}
void posUnDig(){
doNumber(16, row,1); //borra signo negativo
doNumber(a, row,3); //prier parte antes del cero
doNumber(16, row,3); //borra signo negativo
doNumber(b, row,5); //segunda parte num antes de cero
doNumber(14, row,8); //punto decimal
doNumber(c, row,9); //parte decimal
doNumber(15, row,12); //signo de centigrados
}
//*****************************************************************************************//
// doNumber: routine to position number 'num' starting top left at row 'r', column 'c'
void doNumber(byte num, byte r, byte c) {
lcd.setCursor(c,r);
switch(num) {
case 0: lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+1); lcd.write(byte(5)); lcd.write(byte(6));
lcd.setCursor(c,r+2); lcd.write(byte(4)); lcd.write(byte(3)); break;
case 1: lcd.write(byte(0)); lcd.write(byte(1));
lcd.setCursor(c,r+1); lcd.print(" "); lcd.write(byte(5));
lcd.setCursor(c,r+2); lcd.write(byte(0)); lcd.write(byte(4)); break;
case 2: lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+1); lcd.write(byte(2)); lcd.write(byte(3));
lcd.setCursor(c,r+2); lcd.write(byte(4)); lcd.write(byte(2)); break;
case 3: lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+1); lcd.write(byte(0)); lcd.write(byte(3));
lcd.setCursor(c,r+2); lcd.write(byte(2)); lcd.write(byte(3)); break;
case 4: lcd.write(byte(1)); lcd.write(byte(0));
lcd.setCursor(c,r+1); lcd.write(byte(4)); lcd.write(byte(3));
lcd.setCursor(c,r+2); lcd.print(" "); lcd.write(byte(6)); break;
case 5: lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+1); lcd.write(byte(4)); lcd.write(byte(2));
lcd.setCursor(c,r+2); lcd.write(byte(2)); lcd.write(byte(3)); break;
case 6: lcd.write(byte(1)); lcd.print(" ");
lcd.setCursor(c,r+1); lcd.write(byte(4)); lcd.write(byte(2));
lcd.setCursor(c,r+2); lcd.write(byte(4)); lcd.write(byte(3)); break;
case 7: lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+1); lcd.print(" "); lcd.write(byte(6));
lcd.setCursor(c,r+2); lcd.print(" "); lcd.write(byte(6)); break;
case 8: lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+1); lcd.write(byte(4)); lcd.write(byte(3));
lcd.setCursor(c,r+2); lcd.write(byte(4)); lcd.write(byte(3)); break;
case 9: lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+1); lcd.write(byte(4)); lcd.write(byte(3));
lcd.setCursor(c,r+2); lcd.print(" "); lcd.write(byte(6)); break;
case 11:lcd.setCursor(c,r+1); lcd.write(byte(7)); lcd.setCursor(c,r+2); lcd.write(byte(7)); break;
case 13: lcd.print(" "); lcd.print(" "); // minus sign
lcd.setCursor(c,r+1); lcd.write(byte(2)); lcd.write(byte(2));
lcd.setCursor(c,r+2); lcd.print(" "); lcd.print(" "); break;
case 14: lcd.print(" "); lcd.print(" "); // decimal point
lcd.setCursor(c,r+1); lcd.print(" "); lcd.print(" ");
lcd.setCursor(c,r+2); lcd.write(byte(1)); lcd.print(" "); break;
case 15: lcd.write(byte(2)); lcd.write(byte(2)); //centigrade
lcd.setCursor(c,r+1); lcd.write(byte(4)); lcd.write(byte(2));
lcd.setCursor(c,r+2); lcd.print(" ") ; lcd.print(" "); break;
case 16: lcd.print(" " ); lcd.print(" "); //whithe the digit
lcd.setCursor(c,r+1); lcd.print(" "); lcd.print(" ");
lcd.setCursor(c,r+2); lcd.print(" ") ; lcd.print(" "); break;
}
}
@AlexLPD
Copy link
Author

AlexLPD commented Mar 8, 2018

Its the firs iteration, since the big display numbers dont came up with decimal point separator or negative simbol and degre symbol, this is a short program that display any temperature in big digit format, wiil come and wrape it in to a library.
-Alex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment