简体   繁体   中英

Different font size, same LCD screen. Nokia 5110 LCD with arduino uno clock

诺基亚 5110 液晶显示屏(第一行:日期,第二行:小时和分钟,第三行:秒

This is my nokia 5110 lcd arduino clock project. I am attempting to make the font smaller, setTextSize(1), for the seconds only which is the third line on the display. I can change the font size for everything, but not specifically seconds. Anything would be of great help, as I am very new to arduino. Thanks for your time!

//Programa : Teste display Nokia 5110 usando biblioteca Adafruit
//Autor : VINICIUS LOPES

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial date out (DIN)
// pin 5 - date/Command select (D/C)
// pin 6 - LCD chip select (CS/CE)
// pin 7 - LCD reset (RST)

Adafruit_PCD8544 display = Adafruit_PCD8544(3,4,5,6,7);

int second,minute, hour, day, mounth,year; 
unsigned long UtlTime; 

void setup() {
pinMode(2,OUTPUT);
UtlTime=0;    

minute=30;   
hour=6;   
day=9;   
mounth=5;   
year=21;   
Serial.begin(9600);   
  display.begin();
  display.setContrast(80); // Adjust the display contrast
  display.clearDisplay();   //Apaga o buffer e o display
  display.setTextSize(2);  //Seta o tamanho do texto
  display.setTextColor(BLACK); //Seta a cor do texto      
   
display.print("Date \n & \nTime ");   
display.setCursor(0,10);   
display.display();
delay (5000); 


//Configura o hour   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("hour:");
display.display();
Serial.print("\nin between hour:");  
while(hour==0)   {     
if (Serial.available() > 0)     
{       
hour= Serial.parseInt();     
}   
}   
display.print(hour);   
display.display();
delay(1000); 

//Configura a minute   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("minute:");   
display.display();
Serial.print("\nin between minute:"); 
while(hour==0)   
{     
if (Serial.available() > 0)     
{       
minute= Serial.parseInt();     
}   
}   
display.print(minute);   
display.display();
delay(1000);    

//Configura o month   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("month:");
display.display();   
Serial.print("\nin between month:");   
while(mounth==0)   
{     
if (Serial.available() > 0)     
{       
day= Serial.parseInt();     
}   
}   
display.print(mounth);   
display.display();
delay(1000);    

//Configura o mês   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("day:"); 
display.display();  
Serial.print("\nin between day:");  
while(day==0)   
{     
if (Serial.available() > 0)     
{       
day= Serial.parseInt();     
}   
}   
display.print(day);  
 display.display();
delay(1000);    

//Configura o year   
display.clearDisplay();   
display.setCursor(0,0);   
display.print("year:");   
display.display();
Serial.print("\nin between year:");   
while(year==0)   
{     
if (Serial.available() > 0)     
{       
year= Serial.parseInt();     
}   
}   
display.print(year);   

display.display();   
delay(1000);
display.clearDisplay(); 

} 

void loop() 
{   

if(millis()-UtlTime<0)   
{     
UtlTime=millis();   
}   
else   
{  
   
second=int((millis()-UtlTime)/1000);   
}   
if(second>59)   
{     
second=0;     
minute++;     
UtlTime=millis();     
if(minute>59)     
{       
hour++;       
minute=0;       
if(hour>23)       
{         
day++;         
hour=0;         
if(mounth==1||mounth==3||mounth==5||mounth==7||mounth==8||mounth==10||mounth==12)         
{           
if(day>31)           
{             
day=1;             
mounth++;             
if(mounth>12)             
{               
year++;               
mounth=1;             
}           
}         
}         
else if(mounth==2)         
{           
if(year%400==0)           
{             
if(day>29)             
{               
day=1;               
mounth++;             
}           
}           
else if((year%4==0)&&(year%100!=0))           
{             
if(day>29)             
{              
day=1;               
mounth++;             
}           
}           
else           
{             
if(day>28)             
{               
day=1;               
mounth++;             
}           
}         
}         
else         
{           
if(day>30)           
{             
day=1;             
mounth++;           
}         
}       
}     
}   
}    

display.clearDisplay(); 
delay(1000); 
Serial.print(mounth);   
Serial.print("/");   
Serial.print(day);   
Serial.print("/");   
Serial.print(year);   
Serial.println();      

display.setCursor(0,0);   
display.print(" ");   
display.print(mounth);   
display.print("/");   
display.print(day);   
display.print("/");   
display.print(year);

 
display.display();

Serial.print(hour);   
Serial.print(":");   
Serial.print(minute);   
Serial.print(":");   
Serial.print(second);   
Serial.print("\n");   
Serial.println();  
    

display.setCursor(0,16);   
display.print(" ");   
display.print(hour);   
display.print(":");   
display.print(minute);  
display.print("\n -");  
display.print(second); 
display.print("-");
display.display();

char tecla;
tecla = Serial.read();
if(tecla=='1'){
digitalWrite(2,LOW);
}
if(tecla=='2'){
  digitalWrite(2, HIGH);
}

}

setTextSize() sets the 'magnification', not directly the text size, so setTextSize(1) uses the default text size and setTextSize(2) would double the text size.

Adafruit_GFX.cpp :

/*!
    @brief   Set text 'magnification' size. Each increase in s makes 1 pixel
   that much bigger.
    @param  s  Desired text size. 1 is default 6x8, 2 is 12x16, 3 is 18x24, etc
*/
void Adafruit_GFX::setTextSize(uint8_t s) { setTextSize(s, s); }

setTextSize() changes how the pixels of a characters are printed to the display (or in case of Adafruit_PCD8544 to an internal buffer) when using functions like print() allowing us to change the text size for every print call eg

Adafruit_PCD8544 screen = Adafruit_PCD8544(3,4,5,6,7);
//... begin(), setContrast(), etc...
screen.setTextSize(1);
screen.println("Regular");
screen.setTextSize(2);
screen.println("Double");
screen.setTextSize(1);
screen.println("Regular again");
screen.display();

This will display the strings "Regular" and "Regular again" in default text size and the string "Double" double the default text size.

In your code the block:

display.setCursor(0,16);   
display.print(" ");   
display.print(hour);   
display.print(":");   
display.print(minute);
display.print("\n -");  
display.print(second); 
display.print("-");
display.display();

should look something like this:

display.setCursor(0,16);   
display.print(" ");   
display.print(hour);   
display.print(":");   
display.print(minute);
display.setTextSize(1); //Change to smaller text size for seconds since you already use size 2 by default
display.print("\n -");  
display.print(second); 
display.print("-");
display.setTextSize(2) //Change back to larger text size for other values
display.display();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM