I help need to set the time and date with the keypad, using RTC module


hello wanted know how edit rtc time using keyboard

code: [select]


#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 = 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

              /*
               *
               *              part want edit time keyboard
               *
               *
               *
               *
               *
               *
               *
               *
               *
               */
                       
 
         
         
          lcd.clear();
    break;
  }
 
 }
}


void display_tiempo(){
 
  datetime = 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 edit time , date, , @ same time display on display. examples:

display:

code: [select]


set time

1: 00 h



if key pressed, increases hour


display:

code: [select]


set time

2: 00 hour



pressing button, set minutes


display:

code: [select]


set time

2: 00 minutes



if press key, increases minutes


display:

code: [select]


set time

2: 01 minutes




help, i'm new , i'm learning

greetings beforehand.


(translate  google)

use 2 counters, hr , min
you use * increment hr/min , # decrement.

.


Arduino Forum > Using Arduino > Programming Questions > I help need to set the time and date with the keypad, using RTC module


arduino

Comments

Popular posts from this blog

Help with Missing Filename Error?

Using phone battery to power a plane.

more info - Joomla! Forum - community, help and support