#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Define the keypad layout
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect keypad row pins to these Arduino pins
byte colPins[COLS] = {5, 4, 3, 2}; // Connect keypad column pins to these Arduino pins
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Define the LCD address and number of columns and rows
const int LCD_ADDR = 0x27;
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
LiquidCrystal_I2C lcd(LCD_ADDR, LCD_COLS, LCD_ROWS);
int k=0;
int second=0;
int tab[50];
void setup() {
pinMode(10, OUTPUT);
// Initialize the keypad and LCD
keypad.setDebounceTime(50);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Les seconds");
}
void loop() {
int a;
char customKey = keypad.getKey();
int i;
if(customKey){
if(customKey != 'A'){
lcd.setCursor(k, 1);
if (customKey =='0')
a=0;
if (customKey =='1')
a=1;
if (customKey =='2')
a=2;
if (customKey =='3')
a=3;
if (customKey =='4')
a=4;
if (customKey =='5')
a=5;
if (customKey =='6')
a=6;
if (customKey =='7')
a=7;
if (customKey =='8')
a=8;
if (customKey =='9')
a=9;
lcd.print(a);
tab[k]=a;
k++;
}
else if(customKey == 'A'){
for(i=0;i<k;i++)
second+=tab[i]*pow(10,k-i-1);
for(second;second>=0;second--){
lcd.clear();
lcd.print("rest time");
lcd.setCursor(0,1);
lcd.print(second);
delay(1000);
}
tone(10,2620,5000);
lcd.clear();
for(i=0;i<5;i++){
lcd.clear();
lcd.print("alarme is active");
lcd.setCursor(0,1);
lcd.print("stop after ");
lcd.print(5-i);
delay(1000);
}
lcd.clear();
lcd.print("Enter Les seconds");
lcd.setCursor(0,1);
k=0;
}
}
}