Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Sketch ds3231, arduino uno, display 20x4 sda-scl

Progetti, interfacciamento, discussioni varie su questa piattaforma.

Moderatori: Foto UtenteWALTERmwp, Foto Utentexyz

0
voti

[1] Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utenteapollo17 » 23 giu 2023, 19:17

salve, ho i seguenti oggetti: Arduino UNO/ RTC3231 e dislay sda-scl 20x4

Ho già uno sketch che mi da ora e data, ma dato lo spazio a disposizione volevo aggiungere temperatura.
Ancora modificare ora da 12h am/pm in 24h
Qualcuno ha uno sketch pronto? Grazie

Oppure come posso allegare qui lo sketch già in parte modificato?
provato con char *DateTime::toString(char *buffer) const {

char timeBuffer[] = “hh:mm:ss AP”;
ma senza alcun risultato positivo


Codice: Seleziona tutto
#include <Wire.h>                   // for I2C communication
#include <LiquidCrystal_I2C.h>      // for LCD
#include <RTClib.h>                 // for RTC

LiquidCrystal_I2C lcd(0x27, 20, 4); // create LCD with I2C address 0x27, 16 characters per line, 2 lines
RTC_DS3231 rtc;                     // create rtc for the DS3231 RTC module, address is fixed at 0x68
/*
   function to update RTC time using user input
*/
void updateRTC()
{
 
  lcd.clear();  // clear LCD display
  lcd.setCursor(0, 0);
  lcd.print("Edit Mode...");

  // ask user to enter new date and time
  const char txt[6][15] = { "year [4-digit]", "month [1~12]", "day [1~31]",
                            "hours [0~23]", "minutes [0~59]", "seconds [0~59]"};
  String str = "";
  long newDate[6];

  while (Serial.available()) {
    Serial.read();  // clear serial buffer
  }

  for (int i = 0; i < 6; i++) {

    Serial.print("Enter ");
    Serial.print(txt[i]);
    Serial.print(": ");

    while (!Serial.available()) {
      ; // wait for user input
    }

    str = Serial.readString();  // read user input
    newDate[i] = str.toInt();   // convert user input to number and save to array

    Serial.println(newDate[i]); // show user input
  }

  // update RTC
  rtc.adjust(DateTime(newDate[0], newDate[1], newDate[2], newDate[3], newDate[4], newDate[5]));
  Serial.println("RTC Updated!");
}
/*
   function to update LCD text
*/
void updateLCD()
{

  /*
     create array to convert digit days to words:

     0 = Sunday    |   4 = Thursday
     1 = Monday    |   5 = Friday
     2 = Tuesday   |   6 = Saturday
     3 = Wednesday |
  */
  const char dayInWords[7][4] = {"Dom", "Lun", "Mar", "Mer", "Gio", "Vene", "Sab"};
  /*
     create array to convert digit months to words:

     0 = [no use]  |
     1 = January   |   6 = June
     2 = February  |   7 = July
     3 = March     |   8 = August
     4 = April     |   9 = September
     5 = May       |   10 = October
     6 = June      |   11 = November
     7 = July      |   12 = December
  */
  const char monthInWords[13][4] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                                         "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};

  // get time and date from RTC and save in variables
  DateTime rtcTime = rtc.now();

  int ss = rtcTime.second();
  int mm = rtcTime.minute();
  int hh = rtcTime.twelveHour();
  int DD = rtcTime.dayOfTheWeek();
  int dd = rtcTime.day();
  int MM = rtcTime.month();
  int yyyy = rtcTime.year();

  // move LCD cursor to upper-left position
  lcd.setCursor(0, 0);  // cursore no

  // print date in dd-MMM-yyyy format and day of week
  if (dd < 10) lcd.print("0");  // add preceeding '0' if number is less than 10
  lcd.print(dd);
  lcd.print("-");
  lcd.print(monthInWords[MM]);
  lcd.print("-");
  lcd.print(yyyy);

  lcd.print("  ");
  lcd.print(dayInWords[DD]);

  // move LCD cursor to lower-left position
  lcd.setCursor(0, 2); // test ok

  // print time in 12H format
  if (hh < 10) lcd.print("0");
  lcd.print(hh);
  lcd.print(':');

  if (mm < 10) lcd.print("0");
  lcd.print(mm);
  lcd.print(':');

  if (ss < 10) lcd.print("0");
  lcd.print(ss);

  if (rtcTime.isPM()) lcd.print(" PM"); // print AM/PM indication
  else lcd.print(" AM");
}
void setup()
{
  Serial.begin(9600); // initialize serial

  lcd.init();       // initialize lcd
  lcd.backlight();  // switch-on lcd backlight

  rtc.begin();       // initialize rtc
}
void loop()
{
  updateLCD();  // update LCD text

  if (Serial.available()) {
    char input = Serial.read();
    if (input == 'u') updateRTC();  // update RTC time
  }
}

Grazie,

#include <Wire.h>                   // for I2C communication
#include <LiquidCrystal_I2C.h>      // for LCD
#include <RTClib.h>                 // for RTC

LiquidCrystal_I2C lcd(0x27, 20, 4); // create LCD with I2C address 0x27, 16 characters per line, 2 lines
RTC_DS3231 rtc;                     // create rtc for the DS3231 RTC module, address is fixed at 0x68
/*
   function to update RTC time using user input
*/
void updateRTC()
{
 
  lcd.clear();  // clear LCD display
  lcd.setCursor(0, 0);
  lcd.print("Edit Mode...");

  // ask user to enter new date and time
  const char txt[6][15] = { "year [4-digit]", "month [1~12]", "day [1~31]",
                            "hours [0~23]", "minutes [0~59]", "seconds [0~59]"};
  String str = "";
  long newDate[6];

  while (Serial.available()) {
    Serial.read();  // clear serial buffer
  }

  for (int i = 0; i < 6; i++) {

    Serial.print("Enter ");
    Serial.print(txt[i]);
    Serial.print(": ");

    while (!Serial.available()) {
      ; // wait for user input
    }

    str = Serial.readString();  // read user input
    newDate[i] = str.toInt();   // convert user input to number and save to array

    Serial.println(newDate[i]); // show user input
  }

  // update RTC
  rtc.adjust(DateTime(newDate[0], newDate[1], newDate[2], newDate[3], newDate[4], newDate[5]));
  Serial.println("RTC Updated!");
}
/*
   function to update LCD text
*/
void updateLCD()
{

  /*
     create array to convert digit days to words:

     0 = Sunday    |   4 = Thursday
     1 = Monday    |   5 = Friday
     2 = Tuesday   |   6 = Saturday
     3 = Wednesday |
  */
  const char dayInWords[7][4] = {"Dom", "Lun", "Mar", "Mer", "Gio", "Vene", "Sab"};
  /*
     create array to convert digit months to words:

     0 = [no use]  |
     1 = January   |   6 = June
     2 = February  |   7 = July
     3 = March     |   8 = August
     4 = April     |   9 = September
     5 = May       |   10 = October
     6 = June      |   11 = November
     7 = July      |   12 = December
  */
  const char monthInWords[13][4] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
                                         "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};

  // get time and date from RTC and save in variables
  DateTime rtcTime = rtc.now();

  int ss = rtcTime.second();
  int mm = rtcTime.minute();
  int hh = rtcTime.twelveHour();
  int DD = rtcTime.dayOfTheWeek();
  int dd = rtcTime.day();
  int MM = rtcTime.month();
  int yyyy = rtcTime.year();

  // move LCD cursor to upper-left position
  lcd.setCursor(0, 0);  // cursore no

  // print date in dd-MMM-yyyy format and day of week
  if (dd < 10) lcd.print("0");  // add preceeding '0' if number is less than 10
  lcd.print(dd);
  lcd.print("-");
  lcd.print(monthInWords[MM]);
  lcd.print("-");
  lcd.print(yyyy);

  lcd.print("  ");
  lcd.print(dayInWords[DD]);

  // move LCD cursor to lower-left position
  lcd.setCursor(0, 2); // test ok

  // print time in 12H format
  if (hh < 10) lcd.print("0");
  lcd.print(hh);
  lcd.print(':');

  if (mm < 10) lcd.print("0");
  lcd.print(mm);
  lcd.print(':');

  if (ss < 10) lcd.print("0");
  lcd.print(ss);

  if (rtcTime.isPM()) lcd.print(" PM"); // print AM/PM indication
  else lcd.print(" AM");
}
void setup()
{
  Serial.begin(9600); // initialize serial

  lcd.init();       // initialize lcd
  lcd.backlight();  // switch-on lcd backlight

  rtc.begin();       // initialize rtc
}
void loop()
{
  updateLCD();  // update LCD text

  if (Serial.available()) {
    char input = Serial.read();
    if (input == 'u') updateRTC();  // update RTC time
  }
}
Avatar utente
Foto Utenteapollo17
81 1 2 6
Stabilizzato
Stabilizzato
 
Messaggi: 324
Iscritto il: 30 lug 2017, 11:59

0
voti

[2] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utenteapollo17 » 23 giu 2023, 19:57

Codice: Seleziona tutto
#include <Wire.h>                   // for I2C communication
#include <LiquidCrystal_I2C.h>      // for LCD
#include <RTClib.h>                 // for RTC

LiquidCrystal_I2C lcd(0x27, 20, 4); // create LCD with I2C address 0x27, 16 characters per line, 2 lines
RTC_DS3231 rtc;                     // create rtc for the DS3231 RTC module, address is fixed at 0x68
/*
   function to update RTC time using user input
*/
void updateRTC()
{
 
  lcd.clear();  // clear LCD display
  lcd.setCursor(0, 0);
  lcd.print("Edit Mode...");

  // ask user to enter new date and time
  const char txt[6][15] = { "year [4-digit]", "month [1~12]", "day [1~31]",
                            "hours [0~23]", "minutes [0~59]", "seconds [0~59]"};
  String str = "";
  long newDate[6];

  while (Serial.available()) {
    Serial.read();  // clear serial buffer
  }

  for (int i = 0; i < 6; i++) {

    Serial.print("Enter ");
    Serial.print(txt[i]);
    Serial.print(": ");

    while (!Serial.available()) {
      ; // wait for user input
    }

    str = Serial.readString();  // read user input
    newDate[i] = str.toInt();   // convert user input to number and save to array

    Serial.println(newDate[i]); // show user input
  }

  // update RTC
  rtc.adjust(DateTime(newDate[0], newDate[1], newDate[2], newDate[3], newDate[4], newDate[5]));
  Serial.println("RTC Updated!");
}
/*
   function to update LCD text
*/
void updateLCD()
{

  /*
     create array to convert digit days to words:

     0 = Sunday    |   4 = Thursday
     1 = Monday    |   5 = Friday
     2 = Tuesday   |   6 = Saturday
     3 = Wednesday |
  */
  const char dayInWords[7][4] = {"Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"};
  /*
     create array to convert digit months to words:

     0 = [no use]  |
     1 = January   |   6 = June
     2 = February  |   7 = July
     3 = March     |   8 = August
     4 = April     |   9 = September
     5 = May       |   10 = October
     6 = June      |   11 = November
     7 = July      |   12 = December
  */
  const char monthInWords[13][4] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "GIU",
                                         "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};

  // get time and date from RTC and save in variables
  DateTime rtcTime = rtc.now();

  int ss = rtcTime.second();
  int mm = rtcTime.minute();
  int hh = rtcTime.twelveHour();
  int DD = rtcTime.dayOfTheWeek();
  int dd = rtcTime.day();
  int MM = rtcTime.month();
  int yyyy = rtcTime.year();

  // move LCD cursor to upper-left position
  lcd.setCursor(0, 0);  // cursore no

  // print date in dd-MMM-yyyy format and day of week
  if (dd < 10) lcd.print("0");  // add preceeding '0' if number is less than 10
  lcd.print(dd);
  lcd.print("-");
  lcd.print(monthInWords[MM]);
  lcd.print("-");
  lcd.print(yyyy);

  lcd.print("  ");
  lcd.print(dayInWords[DD]);

  // move LCD cursor to lower-left position
  lcd.setCursor(0, 2); // test ok

  // print time in 12H format
  if (hh < 10) lcd.print("0");
  lcd.print(hh);
  lcd.print(':');

  if (mm < 10) lcd.print("0");
  lcd.print(mm);
  lcd.print(':');

  if (ss < 10) lcd.print("0");
  lcd.print(ss);

  if (rtcTime.isPM()) lcd.print(" PM"); // print AM/PM indication
  else lcd.print(" AM");
}
void setup()
{
  Serial.begin(9600); // initialize serial

  lcd.init();       // initialize lcd
  lcd.backlight();  // switch-on lcd backlight

  rtc.begin();       // initialize rtc
}
void loop()
{
  updateLCD();  // update LCD text

  if (Serial.available()) {
    char input = Serial.read();
    if (input == 'u') updateRTC();  // update RTC time
  }
}
Avatar utente
Foto Utenteapollo17
81 1 2 6
Stabilizzato
Stabilizzato
 
Messaggi: 324
Iscritto il: 30 lug 2017, 11:59

0
voti

[3] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utenteboiler » 23 giu 2023, 23:42

Aggiungi la variabile HH (ore in formato 24h) così e poi usala dove vuoi:
Codice: Seleziona tutto
int hh = rtcTime.twelveHour();
int HH = rtcTime.twelveHour() + rtcTime.isPM()?12:0 - (rtcTime.twelveHour()==12)?12:0;


Boiler
Avatar utente
Foto Utenteboiler
26,4k 5 9 13
G.Master EY
G.Master EY
 
Messaggi: 5599
Iscritto il: 9 nov 2011, 12:27

1
voti

[4] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utentenicsergio » 24 giu 2023, 8:31

La proprietà hour dovrebbe ritornare già l'ora in formato 24h:

Codice: Seleziona tutto
int hh = rtcTime.hour();
Avatar utente
Foto Utentenicsergio
4.701 3 9 13
Master
Master
 
Messaggi: 938
Iscritto il: 1 gen 2020, 16:42

0
voti

[5] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utenteboiler » 24 giu 2023, 9:37

Sembrerebbe proprio così: https://adafruit.github.io/RTClib/html/ ... 278335e8d0

Meglio, ancora piú semplice :ok:

Boiler
Avatar utente
Foto Utenteboiler
26,4k 5 9 13
G.Master EY
G.Master EY
 
Messaggi: 5599
Iscritto il: 9 nov 2011, 12:27

0
voti

[6] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utenteapollo17 » 24 giu 2023, 10:38

Non ci riesco, ho provato tutte e tre le vostre cortese risposte, sicuramemte sbaglio in qualche passaggio. Qui parte del listato dove presumo si debba lavorare. Sotto in basso gli errori che ottengo. Sono solo riusciuto a toglire am e pm :(



Codice: Seleziona tutto
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  // print time in 12H format

  // get time and date from RTC and save in variables
  //DateTime rtcTime = rtc.now();
  //int hh = rtcTime.twelveHour();   // errore  int hh = rtcTime.twelveHour();
    uint8_t DateTime::hour  (0-23) const
   

// int HH = rtcTime.twelveHour() + rtcTime.isPM()?12:0 - (rtcTime.twelveHour()==12)?12:0;  // NO errore ma non funziona
// int hh = rtcTime.hour();
  if (hh < 10) lcd.print("0");
  lcd.print(hh);
  lcd.print(':');

  if (mm < 10) lcd.print("0");
  lcd.print(mm);
  lcd.print(':');

  if (ss < 10) lcd.print("0");
  lcd.print(ss);

  //if (rtcTime.isPM()) lcd.print(" PM"); // print AM/PM indication
// else lcd.print(" AM");
}
void setup()
{




R:\ELETTRONICA\ARDUINO_Rom\ARDUINO2023\quadruplo-cucciolo-00\quadruplo-cucciolo-00.ino: In function 'void updateLCD()':

quadruplo-cucciolo-00:113:7: error: redeclaration of 'int hh'

int hh = rtcTime.twelveHour(); // errore int hh = rtcTime.twelveHour();

^~
note: 'int hh' previously declared here

int hh = rtcTime.twelveHour();

^~

===================================================================
error: expected primary-expression before '^' token ^~

^
error: expected primary-expression before 'int'
int HH = rtcTime.twelveHour() + rtcTime.isPM()?12:0 - (rtcTime.twelveHour()==12)?12:0;
^~~

exit status 1

redeclaration of 'int hh'


==================================================

int hh = rtcTime.hour();
note: 'int hh' previously declared here
int hh = rtcTime.twelveHour();
^~
exit status 1
redeclaration of 'int hh'

Infiner con int HH = rtcTime.twelveHour() + rtcTime.isPM()?12:0 - (rtcTime.twelveHour()==12)?12:0; no errore ma nessuno effetto
Avatar utente
Foto Utenteapollo17
81 1 2 6
Stabilizzato
Stabilizzato
 
Messaggi: 324
Iscritto il: 30 lug 2017, 11:59

0
voti

[7] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utentenicsergio » 24 giu 2023, 11:40

Nel metodo updateLCD() devi sostituire la riga

Codice: Seleziona tutto
int hh = rtcTime.twelveHour();


con

Codice: Seleziona tutto
int hh = rtcTime.hour();


e poi, come hai già fatto, commentare la visualizzazione di AM/PM, ultime due righe sempre di updateLCD().
Avatar utente
Foto Utentenicsergio
4.701 3 9 13
Master
Master
 
Messaggi: 938
Iscritto il: 1 gen 2020, 16:42

0
voti

[8] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utenteapollo17 » 24 giu 2023, 12:25

Codice: Seleziona tutto
  // move LCD cursor to lower-left position
  lcd.setCursor(0, 3);
  lcd.print ("Ora:");
  lcd.setCursor(5, 3); //
  int hh = rtcTime.hour();  // sostituito
  // print time in 12H format
  if (hh < 10) lcd.print("0");
  lcd.print(hh);
  lcd.print(':');

  if (mm < 10) lcd.print("0");
  lcd.print(mm);
  lcd.print(':');

  if (ss < 10) lcd.print("0");
  lcd.print(ss);

  if (rtcTime.isPM()) lcd.print(" PM"); // print AM/PM indication
  else lcd.print(" AM");
}
void setup()



sostituito per chiarezza partiamo dalla situazione sopra, mi da errore sotto riportato. Cosa devo cancellare?
================================================================================
Errore: Arduino:1.8.19 (Windows Store 1.8.57.0) (Windows 10), Scheda:"Arduino Uno"

R:\ELETTRONICA\ARDUINO_Rom\ARDUINO2023\triplo_cucciolo_us__basee\triplo_cucciolo_us__basee.ino: In function 'void updateLCD()':

triplo_cucciolo_us__basee:108:7: error: redeclaration of 'int hh'

int hh = rtcTime.hour();

^~

R:\ELETTRONICA\ARDUINO_Rom\ARDUINO2023\triplo_cucciolo_us__basee\triplo_cucciolo_us__basee.ino:82:7: note: 'int hh' previously declared here

int hh = rtcTime.twelveHour();

^~

exit status 1

redeclaration of 'int hh'
Avatar utente
Foto Utenteapollo17
81 1 2 6
Stabilizzato
Stabilizzato
 
Messaggi: 324
Iscritto il: 30 lug 2017, 11:59

0
voti

[9] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utentenicsergio » 24 giu 2023, 12:37

Sono da cellulare e non riesco a postare l'intero sketch, la riga da sostituire è poco più su della porzione di codice che hai allegato, mentre tu hai aggiunto la riga definendo una seconda volta hh, da qui l'errore.
Avatar utente
Foto Utentenicsergio
4.701 3 9 13
Master
Master
 
Messaggi: 938
Iscritto il: 1 gen 2020, 16:42

0
voti

[10] Re: Sketch ds3231, arduino uno, display 20x4 sda-scl

Messaggioda Foto Utenteapollo17 » 24 giu 2023, 14:10

sono da cellulare...


Perfetto, grazie . Riga 79 ok orario 24 h

Con calma vorrei aggiungere temperatura riga3/
In quote lo sketck completo e funzionante






Codice: Seleziona tutto
#include <Wire.h>                   // for I2C communication
#include <LiquidCrystal_I2C.h>      // for LCD
#include <RTClib.h>                 // for RTC

LiquidCrystal_I2C lcd(0x27, 20, 4); // create LCD with I2C address 0x27, 16 characters per line, 2 lines
RTC_DS3231 rtc;                     // create rtc for the DS3231 RTC module, address is fixed at 0x68
/*
   function to update RTC time using user input
*/
void updateRTC()
{
 
  lcd.clear();  // clear LCD display
  lcd.setCursor(0, 0);
  lcd.print("Edit Mode...");

  // ask user to enter new date and time
  const char txt[6][15] = { "year [4-digit]", "month [1~12]", "day [1~31]",
                            "hours [0~23]", "minutes [0~59]", "seconds [0~59]"};
  String str = "";
  long newDate[6];

  while (Serial.available()) {
    Serial.read();  // clear serial buffer
  }

  for (int i = 0; i < 6; i++) {

    Serial.print("Enter ");
    Serial.print(txt[i]);
    Serial.print(": ");

    while (!Serial.available()) {
      ; // wait for user input
    }

    str = Serial.readString();  // read user input
    newDate[i] = str.toInt();   // convert user input to number and save to array

    Serial.println(newDate[i]); // show user input
  }

  // update RTC
  rtc.adjust(DateTime(newDate[0], newDate[1], newDate[2], newDate[3], newDate[4], newDate[5]));
  Serial.println("RTC Updated!");
}
/*
   function to update LCD text
*/
void updateLCD()
{

  /*
     create array to convert digit days to words:

     0 = Sunday    |   4 = Thursday
     1 = Monday    |   5 = Friday
     2 = Tuesday   |   6 = Saturday
     3 = Wednesday |
  */
  const char dayInWords[7][8] = {"Dom", "Lun", "Mar", "Mer", "Gio", "Venerdi", "Sabato"};
  /*
     create array to convert digit months to words:

     0 = [no use]  |
     1 = January   |   6 = June
     2 = February  |   7 = July
     3 = March     |   8 = August
     4 = April     |   9 = September
     5 = May       |   10 = October
     6 = June      |   11 = November
     7 = July      |   12 = December
  */
  const char monthInWords[13][4] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "GIU",
                                         "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};

  // get time and date from RTC and save in variables
  DateTime rtcTime = rtc.now();
int hh = rtcTime.hour();
  int ss = rtcTime.second();
  int mm = rtcTime.minute();
  // int hh = rtcTime.twelveHour();   versione 12 h
 
  int DD = rtcTime.dayOfTheWeek();
  int dd = rtcTime.day();
  int MM = rtcTime.month();
  int yyyy = rtcTime.year();

  // move LCD cursor to upper-left position
  lcd.setCursor(0, 0);  // cursore no
  lcd.print("Data:");
  // print date in dd-MMM-yyyy format and day of week
  lcd.setCursor(6, 0);
 
  if (dd < 10) lcd.print("0");  // add preceeding '0' if number is less than 10
  lcd.print(dd);
  lcd.print("-");
  lcd.print(monthInWords[MM]);
  lcd.print("-");
  lcd.print(yyyy);
  lcd.setCursor(7, 1);
  lcd.print("  ");
  lcd.print(dayInWords[DD]);


  // move LCD cursor to lower-left position
  lcd.setCursor(0, 3);
  lcd.print ("Ora :");
  lcd.setCursor(6, 3); // test ok  // primo valore sposta da sx a dx primo carattere sulla stessa riga /secondo valore sposta intera riga partendo da 0
  //int hh = rtcTime.hour();
  // print time in 12H format
  if (hh < 10) lcd.print("0");
  lcd.print(hh);
  lcd.print(':');

  if (mm < 10) lcd.print("0");
  lcd.print(mm);
  lcd.print(':');

  if (ss < 10) lcd.print("0");
  lcd.print(ss);

  // if (rtcTime.isPM()) lcd.print(" PM"); // print AM/PM indication
// else lcd.print(" AM");
}
void setup()
{
  Serial.begin(9600); // initialize serial

  lcd.init();       // initialize lcd
  lcd.backlight();  // switch-on lcd backlight

  rtc.begin();       // initialize rtc
}
void loop()
{
  updateLCD();  // update LCD text

  if (Serial.available()) {
    char input = Serial.read();
    if (input == 'u') updateRTC();  // update RTC time
  }
}
Avatar utente
Foto Utenteapollo17
81 1 2 6
Stabilizzato
Stabilizzato
 
Messaggi: 324
Iscritto il: 30 lug 2017, 11:59

Prossimo

Torna a Arduino

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite