Change " Button" to " Keypad 4*4"

I have a code :Arduino real time clock with DS1307

#include <LiquidCrystal.h>
// include Wire library code (needed for I2C protocol devices)
#include <Wire.h>

// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
pinMode(8, INPUT_PULLUP); // button1 is connected to pin 8
pinMode(9, INPUT_PULLUP); // button2 is connected to pin 9
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
Wire.begin(); // Join i2c bus
}

char Time[] = "TIME: : : ";
char Calendar[] = "DATE: / /20 ";
byte i, second, minute, hour, date, month, year;

void DS1307_display(){
// Convert BCD to decimal
second = (second >> 4) * 10 + (second & 0x0F);
minute = (minute >> 4) * 10 + (minute & 0x0F);
hour = (hour >> 4) * 10 + (hour & 0x0F);
date = (date >> 4) * 10 + (date & 0x0F);
month = (month >> 4) * 10 + (month & 0x0F);
year = (year >> 4) * 10 + (year & 0x0F);
// End conversion
Time[12] = second % 10 + 48;
Time[11] = second / 10 + 48;
Time[9] = minute % 10 + 48;
Time[8] = minute / 10 + 48;
Time[6] = hour % 10 + 48;
Time[5] = hour / 10 + 48;
Calendar[14] = year % 10 + 48;
Calendar[13] = year / 10 + 48;
Calendar[9] = month % 10 + 48;
Calendar[8] = month / 10 + 48;
Calendar[6] = date % 10 + 48;
Calendar[5] = date / 10 + 48;
lcd.setCursor(0, 0);
lcd.print(Time); // Display time
lcd.setCursor(0, 1);
lcd.print(Calendar); // Display calendar
}
void blink_parameter(){
byte j = 0;
while(j < 10 && digitalRead(8) && digitalRead(9)){
j++;
delay(25);
}
}
byte edit(byte x, byte y, byte parameter){
char text[3];
while(!digitalRead(8)); // Wait until button (pin #8) released
while(true){
while(!digitalRead(9)){ // If button (pin #9) is pressed
parameter++;
if(i == 0 && parameter > 23) // If hours > 23 ==> hours = 0
parameter = 0;
if(i == 1 && parameter > 59) // If minutes > 59 ==> minutes = 0
parameter = 0;
if(i == 2 && parameter > 31) // If date > 31 ==> date = 1
parameter = 1;
if(i == 3 && parameter > 12) // If month > 12 ==> month = 1
parameter = 1;
if(i == 4 && parameter > 99) // If year > 99 ==> year = 0
parameter = 0;
sprintf(text,"%02u", parameter);
lcd.setCursor(x, y);
lcd.print(text);
delay(200); // Wait 200ms
}
lcd.setCursor(x, y);
lcd.print(" "); // Display two spaces
blink_parameter();
sprintf(text,"%02u", parameter);
lcd.setCursor(x, y);
lcd.print(text);
blink_parameter();
if(!digitalRead(8)){ // If button (pin #8) is pressed
i++; // Increament 'i' for the next parameter
return parameter; // Return parameter value and exit
}
}
}

void loop() {
if(!digitalRead(8)){ // If button (pin #8) is pressed
i = 0;
hour = edit(5, 0, hour);
minute = edit(8, 0, minute);
date = edit(5, 1, date);
month = edit(8, 1, month);
year = edit(13, 1, year);
// Convert decimal to BCD
minute = ((minute / 10) << 4) + (minute % 10);
hour = ((hour / 10) << 4) + (hour % 10);
date = ((date / 10) << 4) + (date % 10);
month = ((month / 10) << 4) + (month % 10);
year = ((year / 10) << 4) + (year % 10);
// End conversion
// Write data to DS1307 RTC
Wire.beginTransmission(0x68); // Start I2C protocol with DS1307 address
Wire.write(0); // Send register address
Wire.write(0); // Reset sesonds and start oscillator
Wire.write(minute); // Write minute
Wire.write(hour); // Write hour
Wire.write(1); // Write day (not used)
Wire.write(date); // Write date
Wire.write(month); // Write month
Wire.write(year); // Write year
Wire.endTransmission(); // Stop transmission and release the I2C bus
delay(200); // Wait 200ms
}
Wire.beginTransmission(0x68); // Start I2C protocol with DS1307 address
Wire.write(0); // Send register address
Wire.endTransmission(false); // I2C restart
Wire.requestFrom(0x68, 7); // Request 7 bytes from DS1307 and release I2C bus at end of reading
second = Wire.read(); // Read seconds from register 0
minute = Wire.read(); // Read minuts from register 1
hour = Wire.read(); // Read hour from register 2
Wire.read(); // Read day from register 3 (not used)
date = Wire.read(); // Read date from register 4
month = Wire.read(); // Read month from register 5
year = Wire.read(); // Read year from register 6
DS1307_display(); // Diaplay time & calendar
delay(50); // Wait 50ms
}

Everybody can help me change "use Button in this code" to " use Keypad 4*4". Thanks all! :slight_smile: :slight_smile:

OK, well first, you need to post the code properly. Did you look at what you posted?

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can as you now see, be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only between complete functional blocks.