EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / how to get keypad inputs to initialise the time in the clock

how to get keypad inputs to initialise the time in the clock

|

Microcontroller › Arduino › how to get keypad inputs to initialise the time in the clock

  • This topic has 1 reply, 1 voice, and was last updated 9 years, 10 months ago by sunil.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • April 22, 2016 at 5:12 pm #4427
    sunil
    Participant
    Hi,
     
    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.
     
     
     
    #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;
     }
    }
    April 23, 2016 at 6:08 am #13888
    sunil
    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;
     }
    }
  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • excessive technology in multimeters March 9, 2026
  • energising a solenoid March 9, 2026
  • Pnp transistor query March 9, 2026
  • Project boxes March 8, 2026
  • MCS-51 Development Ecosystem March 8, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise