Microcontroller › Arduino › how to get keypad inputs to initialise the time in the clock › How to get keypad inputs to initialise the time in the LCD clock
April 23, 2016 at 6:08 am
#13888
Participant
The following code written for LCD based hourly Alarm Digital clock.
Here, the current time is initialised in the program itself. But i want to know how can we initialise the time from keypad?
Can anyone please help??
Thanks in advance…
#include <Keypad.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//RS,EN,D4,D5,D6,D7
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 0, 1, 2, 3 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 4, 5, 6, 7 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int k,hi=22,mi=24,si=45,h,m,s,s1,s2,m1,m2,h1,h2;
int buzz = A1;
void setup()
{
for(int k=8;k<14;k++)
{
pinMode(k,OUTPUT);//pins 8-14 are enabled as output
}
lcd.begin(16, 2);//initializing LCD
pinMode(buzz, OUTPUT);
}
void loop()
{
for(h=hi; h<24; h++,m=0) //initialise the 'h' value to current hour
{
for(m=mi; m<60; m++) //initilaise the 'm' value to current minute
{
for(s=si; s<60; s++)
{
lcd.clear();
lcd.print("TIME # ");
lcd.setCursor(0,1);
h1=h/10;
h2=h%10;
m1=m/10;
m2=m%10;
s1=s/10;
s2=s%10;
lcd.setCursor(7,0);
lcd.print(h1);
lcd.setCursor(8,0);
lcd.print(h2);
lcd.setCursor(9,0);
lcd.print(":");
lcd.setCursor(10,0);
lcd.print(m1);
lcd.setCursor(11,0);
lcd.print(m2);
lcd.setCursor(12,0);
lcd.print(":");
lcd.setCursor(13,0);
lcd.print(s1);
lcd.setCursor(14,0);
lcd.print(s2);
delay(1000);
if(m==0 && s<15)
digitalWrite(buzz, HIGH);
else
digitalWrite(buzz, LOW);
si=0;
}
mi=0;
}
hi=0;
}
}