Question: using Arduino. I'm trying to set Date/Time manully by the keypad to print that on LCD . i made the code but need some help

using Arduino. I'm trying to set Date/Time manully by the keypad to print that on LCD . i made the code but need some help to make it work. here is the code below :

#include

#include

#include

#include

#include

// The wire library is sometimes need you can remove it unless your compiler complains

// about it as a missing library

#include

// Pin Definitions for the LCD Display

#define lcdSDAPin A4

#define lcdSCLPin A5

#define lcdAddress 0x3F

#define lcdColumns 16

#define lcdRows 2

//Pin definitions for the 4x4 matrix keypad

//UPDATE the numbers to match the pin connections from YOUR keypad to YOUR Arduino

#define Row1Pin 9

#define Row2Pin 8

#define Row3Pin 7

#define Row4Pin 6

#define Col1Pin 5

#define Col2Pin 4

#define Col3Pin 3

#define Col4Pin 2

char customKey;

const byte ROWS = 4; // Four rows on the keypad

const byte COLS = 4; // Four columns on the keypad

// Define the keymap for the keypad

char keys[ROWS][COLS] = {

{ '1', '2', '3', 'A' },

{ '4', '5', '6', 'B' },

{ '7', '8', '9', 'C' },

{ '*', '0', '#', 'D' }

};

byte rowPins[ROWS] = { Row1Pin, Row2Pin, Row3Pin, Row4Pin }; // Connect to the row pinouts of the keypad

byte colPins[COLS] = { Col1Pin, Col2Pin, Col3Pin, Col4Pin }; // Connect to the column pinouts of the keypad

// Initialize the keypad object

Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Set the pins on the I2C chip used for LCD connections:

// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol

LiquidCrystal_I2C lcd(lcdAddress, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

unsigned long timeNow = 0;

unsigned long timeLast = 0;

//Time start Settings:

int startingHour = 12; // set your starting hour here, not below at int hour. This ensures accurate daily correction of time

/*

int seconds = 0;

int minutes = 10;

int hours = startingHour;

*/

long firstDigit = 0;

long secondDigit = 0;

byte second ;

byte hour ;

byte minute ;

//Accuracy settings

int dailyErrorFast = 0; // set the average number of milliseconds your microcontroller's time is fast on a daily basis

int dailyErrorBehind = 0; // set the average number of milliseconds your microcontroller's time is behind on a daily basis

int correctedToday = 1;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

lcd.begin(lcdColumns, lcdRows);

lcd.backlight();

lcd.clear();

}

void loop() {

// put your main code here, to run repeatedly:

//*************************************************

customKey = customKeypad.getKey();

if (customKey) {

lcd.setCursor(1, 1);

firstDigit = firstDigit * 10 + (customKey - '0');

lcd.print(firstDigit);

while ( 1 )

{

customKey = customKeypad.getKey();

if (customKey >= '0' && customKey <= '9')

{

secondDigit = secondDigit * 10 + (customKey - '0');

lcd.setCursor(0, 2);

lcd.print(secondDigit);

}

}

}

//************************************************

timeNow = millis() / 1000; // the number of milliseconds that have passed since boot

second = timeNow - timeLast;//the number of seconds that have passed since the last time 60 seconds was reached.

if (second == 60) {

timeLast = timeNow;

minute = minute + 1;

}

//if one minute has passed, start counting milliseconds from zero again and add one minute to the clock.

if (minute == 60) {

minute = customKey;

minute = 0;

hour = hour + 1;

}

if (hour == 12) {

hour = customKey;

hour = 0;

}

lcd.setCursor(0, 0);

lcd.print("The time is:");

lcd.setCursor(0, 1);

lcd.print(hour);

lcd.setCursor(2, 1);

lcd.print(":");

lcd.print(minute);

lcd.setCursor(5, 1);

lcd.print(":");

lcd.print(second);

}

/*

customKey = customKeypad.getKey();

if (customKey){

lcd.setCursor(1,1);

firstDigit = firstDigit * 10 + (customKey - '0');

lcd.print(firstDigit);

while( 1 )

{

customKey = customKeypad.getKey();

if(customKey >= '0' && customKey <= '9')

{

second = second * 10 + (customKey - '0');

lcd.setCursor(0,2);

lcd.print(second);

}

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!