PitLiquidCristal_I2C

L'utilizzo del display a cristalli liquidi PitLiquidCristal_IC2.

Prova del ricevitore a infrarossi

Cosa serve:

  • Display a cristalli liquidi LiquidCristal_IC2
  • cavetti

Codice sorgente:


//Compatible with the Arduino IDE 1.0
//Library version:1.1
//www.zappoco.altervista.org
//aggiunte routine di stampa
//  lcd_PrintStringa (String stringText, int PX, int PY)
//  lcd_PrintChar (char charText[], int PX, int PY)
//  ItoS (int ii, int nn)
#include  
#include 

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

int lcdXmax = 16;
int lcdYmax = 2;

int indice;

void setup()
{
  lcd.init();                      // initialize the lcd 
 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.println("Hello,Zappoco!");
}

void loop()
{
  indice = indice +1;
  // lcd.clear();
  lcd_PrintStringa ("Hello,Zappoco!", 0, 0);
  lcd_PrintStringa ("Ciclo: " + ItoS (indice, 3), 0, 1);
  
  delay (1000);
}

void lcd_PrintStringa (String stringText, int PX, int PY)
{
   int n = 0;
   int x,y  ;
   boolean chEnd = false;
   String ch;

   int sl = stringText.length();
          
   for (n=0; n < sl ; n++)
    {
      x = PX + n;
      y = PY;
      ch = stringText.substring(n ,n + 1); // estrae stringa da n a n+1;
      
      if (x < lcdXmax && y < lcdYmax)
      {
        lcd.setCursor(x, y);
        lcd.print(ch);
      }
    
    } 
 }

 void lcd_PrintChar (char charText[], int PX, int PY)
{
   int n = 0;
   int x,y  ;
   char ch;
   boolean chEnd = false;
   
         
   for (n=0; n < lcdXmax ; n++)
    {
      x = PX + n;
      y = PY;
      ch = charText[n];
      if (ch == 0 || chEnd == true)
      {
        ch = 32;
        chEnd == true;
      }
      
      if (x < lcdXmax && y < lcdYmax)
      {
        lcd.setCursor(x, y);
        lcd.print(ch);
      }
    
      //Serial.print ("n ");
      //Serial.print (n);
      //Serial.print (" - ");
      //Serial.print (char(Stringa[n]));
      //delay(100);
    } 
    //Serial.println ();
 }

String ItoS (int ii, int nn)
{
   String gg;
   int ll;
   gg.concat(ii);
   gg = "          " + gg;
   ll = gg.length(); 
   gg = gg.substring(ll - nn,ll);
   return gg;

}


 

 

 

Scarica tutto quello che serve:

 

 

 

ZappocoS, 10 febbraio 2018