Hello I wanted to know how to edit the RTC time using keyboard
#include <RTClib.h> //library: https://github.com/adafruit/RTClib
#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); //pines del arduino al LCD (RS E D4 D5 D6 D7)
//Definición de filas y columnas
const byte Filas = 4; //Cuatro filas
const byte Cols = 4; //Cuatro columnas
//Definición de los pines
byte Pins_Filas[] = {3, 2, 1, 0}; //Pines Arduino para las filas
byte Pins_Cols[] = {4, 5, 6, 7}; // Pines Arduino para las columnas
//Definición de las teclas
char Teclas [ Filas ][ Cols ] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
//Se crea una instancia llamada Teclado1 y el cual asignara las teclas que tenemos en el arreglo "Teclas" y le decimos
//que se han conectados los pines de las filas y columnas
Keypad kpd = Keypad(makeKeymap(Teclas), Pins_Filas, Pins_Cols, Filas, Cols);
int Fecha;
int Mes;
int Ano;
int Hora;
int Minutos;
int Segundos;
void display_tiempo();
void display_posicion(int digitos);
char Teclado ();
char kp;
RTC_DS1307 RTC;
void setup()
{
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__));
lcd.begin(16, 4); //Configura el LCD con el numero de columas y filas. Para un LCD 16x4: 16 columnas y 4 filas.
lcd.display(); //Enciende el display
lcd.clear();
pinMode(A0, OUTPUT);
digitalWrite(A0, LOW);
}
void loop()
{
display_tiempo();
lcd.setCursor(0,3); lcd.print ("Press *");
char Tecla = kpd.getKey();
if (Tecla == '*'){
lcd.clear();
lcd.setCursor(0,1); lcd.print ("Menu 1");
lcd.setCursor(0,2); lcd.print ("Menu 2");
kp = Teclado ();
switch(kp){
case '1':
lcd.clear();
lcd.setCursor(0,2); lcd.print ("1. LedOn");
lcd.setCursor(0,3); lcd.print ("2. LedOff");
kp = Teclado ();
switch(kp){
case '1':
lcd.clear();
lcd.setCursor(0,2); lcd.print ("LedOn");
digitalWrite(A0, HIGH);
delay(50);
lcd.clear();
break;
case '2':
lcd.clear();
lcd.setCursor(0,2); lcd.print ("ledoff");
digitalWrite(A0, LOW);
delay(50);
lcd.clear();
break;
}
break;
case '2':
lcd.clear();
lcd.setCursor(0,0); lcd.print ("set time");
DateTime now = RTC.now(); //obtiene datos del modulo RTC
lcd.setCursor(0,1);
display_posicion(Hora); //Imprime Hora
lcd.print(':');
display_posicion(Minutos); //Imprime Minutos
lcd.print(':');
display_posicion(Segundos); //Imprime Segundos
/*
*
* this part is where I want to edit the time with keyboard
*
*
*
*
*
*
*
*
*
*/
lcd.clear();
break;
}
}
}
void display_tiempo(){
DateTime now = RTC.now(); //obtiene datos del modulo RTC
Fecha = now.day();
Mes = now.month();
Ano = now.year();
Hora = now.hour();
Minutos = now.minute();
Segundos = now.second();
lcd.setCursor(0,0);
display_posicion(Fecha); //Imprime fecha
lcd.print('/');
display_posicion(Mes); //Imprime Mes
lcd.print('/');
display_posicion(Ano); //Imprime Año
lcd.setCursor(0,1);
display_posicion(Hora); //Imprime Hora
lcd.print(':');
display_posicion(Minutos); //Imprime Minutos
lcd.print(':');
display_posicion(Segundos); //Imprime Segundos
}
void display_posicion(int digitos){
if(digitos < 10){lcd.print("0");}
lcd.print(digitos);
}
char Teclado ()
{
do{
char Tecla = kpd.getKey();
if (Tecla != NO_KEY)
{
return Tecla;
}
} while (1);
}
I want to edit the time and date, and at the same time display on the display. examples:
Display:
set time
1: 00 h
If a key is pressed, increases hour
Display:
set time
2: 00 hour
Pressing another button, set the minutes
Display:
set time
2: 00 minutes
if you press a key, increases the minutes
Display:
set time
2: 01 minutes
Help, I'm new and I'm learning
Greetings beforehand.
(translate by google)