I'm using arduino uno for simulation
here is the full sketch
#include <Adafruit_LiquidCrystal.h>
#include <Keypad.h>
int trigPin = 11; // TRIG pin
int echoPin = 10; // ECHO pin
float duration_us, distance_cm;
Adafruit_LiquidCrystal lcd_1(0);
const int ROW_NUM = 4; // four rows
const int COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // connect to the column pinouts of the keypad
Keypad customKeypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
byte Alef1[] = {
B00100,
B00110,
B00110,
B00100,
B00100,
B00100,
B00100,
B00100
};
byte Dal1[] = {
B00000,
B00000,
B01100,
B00010,
B00001,
B11110,
B00000,
B00000
};
byte Khaa3[] = {
B00000,
B00010,
B11000,
B01100,
B00010,
B11111,
B00000,
B00000
};
byte Laam3[] = {
B00000,
B00010,
B00010,
B00010,
B00010,
B10010,
B11111,
B00000
};
byte Rhaa1[] = {
B00000,
B00000,
B00000,
B00001,
B00010,
B00100,
B11000,
B00000
};
byte Qaaf1[] = {
B01010,
B00000,
B00110,
B01001,
B01001,
B00111,
B00001,
B11111
};
byte Meem2[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00110,
B11111,
B00110
};
byte Geem1[] = {
B00000,
B11100,
B00110,
B00011,
B11111,
B00000,
B00100,
B00000
};
byte Wao2[] = {
B00000,
B01100,
B10010,
B10010,
B01111,
B00100,
B01000,
B10000
};
byte Laam1[] = {
B00011,
B00011,
B00011,
B00011,
B00011,
B00011,
B11111,
B11111
};
byte Kaaf1[] = {
B00001,
B00101,
B01001,
B11101,
B00001,
B10001,
B11111,
B00000
};
byte Seen3[] = {
B00000,
B00000,
B00000,
B10101,
B10101,
B10101,
B10101,
B11111
};
byte Noon2[] = {
B00000,
B00100,
B00100,
B00000,
B10010,
B10010,
B10010,
B11111
};
byte kaaf2[] = {
B00001,
B00010,
B00100,
B01000,
B00100,
B00010,
B11111,
B00000
};
void setup() {
Serial.begin(4800);
lcd_1.begin(16,2);
displayscreen();
pinMode(trigPin, OUTPUT); // config trigger pin to output mode
pinMode(echoPin, INPUT); // config echo pin to input mode
}
void Height(){
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration_us = pulseIn(echoPin, HIGH);
distance_cm = 0.017 * duration_us;
lcd_1.clear();
lcd_1.setCursor(0, 1);
lcd_1.print("Height: ");
lcd_1.print(distance_cm);
}
void displayscreen(){
lcd_1.setCursor(4,0);
lcd_1.print("*iScale*");
lcd_1.setCursor(2 ,1);
lcd_1.print("!Your Scale!");
lcd_1.scrollDisplayLeft();
delay(200);
lcd_1.scrollDisplayRight();
}
/*void agetext(){
lcd_1.createChar(12, Alef1);
lcd_1.setCursor(16,0);
lcd_1.write(12);
lcd_1.createChar(13, Dal1);
lcd_1.setCursor(15,0);
lcd_1.write(13);
lcd_1.createChar(14, Khaa3);
lcd_1.setCursor(14,0);
lcd_1.write(14);
lcd_1.createChar(15, Laam3);
lcd_1.setCursor(13,0);
lcd_1.write(15);
lcd_1.createChar(16, Seen3);
lcd_1.setCursor(10,0);
lcd_1.write(16);
lcd_1.createChar(17, Noon2);
lcd_1.setCursor(9,0);
lcd_1.write(17);
lcd_1.createChar(18, Kaaf1);
lcd_1.setCursor(8,0);
lcd_1.write(18);
}*/
void loop(){
static unsigned long lastKeypressTime = 0; // initialize the lastKeypressTime variable
char customKey = customKeypad.getKey(); // variable for the input key
if (customKey) //if there is any input
{
lcd_1.clear();
lastKeypressTime = millis(); // update the lastKeypressTime variable with the current time
//lcd_1.setCursor(15,0);
//lcd_1.print("Enter your PhoneNo.:");
lcd_1.createChar(0, Alef1);
lcd_1.setCursor(15,0);
lcd_1.write(0);
lcd_1.createChar(1, Dal1);
lcd_1.setCursor(14,0);
lcd_1.write(1);
lcd_1.createChar(2, Khaa3);
lcd_1.setCursor(13,0);
lcd_1.write(2);
lcd_1.createChar(3, Laam3);
lcd_1.setCursor(12,0);
lcd_1.write(3);
lcd_1.createChar(4, Rhaa1);
lcd_1.setCursor(10,0);
lcd_1.write(4);
lcd_1.createChar(5, Qaaf1);
lcd_1.setCursor(9,0);
lcd_1.write(5);
lcd_1.createChar(6, Meem2);
lcd_1.setCursor(8,0);
lcd_1.write(6);
lcd_1.createChar(7, Kaaf1);
lcd_1.setCursor(7,0);
lcd_1.write(7);
Serial.print("Enter your PhoneNo.: ");
class String PhoneString = ""; // Initialize an empty string to hold the user's age
// Wait for the user to enter their Phone (up to 10 seconds)
while (millis() - lastKeypressTime <= 10000) {
char PhoneKey = customKeypad.getKey();
// Initialize if a key is pressed
if (PhoneKey) {
lastKeypressTime = millis();
Serial.print(PhoneKey);
PhoneString += PhoneKey; // Append the entered digit to the age string
lcd_1.setCursor(2,1);
lcd_1.print(PhoneString);
//PhoneString += PhoneKey;
// If the age string has two digits, categorize the age
if (PhoneString.length() == 11) {
// Print the user's age and age group
lcd_1.clear();
lcd_1.setCursor(1,0);
lcd_1.print("Your Phone is: ");
lcd_1.setCursor(2,1);
lcd_1.print(PhoneString);
//delay(1000);
// Convert the age string to an integer
int Phone = PhoneString.toInt();
//lastKeypressTime = 0;
//if (millis() -lastKeypressTime > 10000) {
PhoneString = "";
delay(1000);
Age3();
}
}
}
}
// }
}
int Age3() {
int iAge;
lcd_1.clear();
// lcd_1.print("Enter Your Age :");
lcd_1.createChar(0, Alef1);
lcd_1.setCursor(15,0);
lcd_1.write(0);
/*
lcd_1.createChar(1, Dal1);
lcd_1.setCursor(14,0);
lcd_1.write(1);
lcd_1.createChar(2, Khaa3);
lcd_1.setCursor(13,0);
lcd_1.write(2);*/
lcd_1.createChar(3, Laam3);
lcd_1.setCursor(14,0);
lcd_1.write(3);
lcd_1.createChar(4, Seen3);
lcd_1.setCursor(13,0);
lcd_1.write(4);
lcd_1.createChar(5, Noon2);
lcd_1.setCursor(12,0);
lcd_1.write(5);
/*
lcd_1.createChar(6, Kaaf1);
lcd_1.setCursor(8,0);
lcd_1.write(6); */
lcd_1.setCursor(4, 1);
char Key = NO_KEY;
while (Key == NO_KEY) {
Key = customKeypad.getKey();
if (Key > '0' && Key <= '9') iAge = Key - '0';
else Key = NO_KEY;
}
Serial.print(Key);
lcd_1.print(Key);
Key = NO_KEY;
while (Key == NO_KEY) {
Key = customKeypad.getKey();
if (Key >= '0' && Key <= '9') iAge = iAge * 10 + Key - '0';
else Key = NO_KEY;
}
Serial.print(Key);
lcd_1.println(Key);
lcd_1.clear();
lcd_1.setCursor(1, 0);
lcd_1.print("Your Age is: ");
lcd_1.setCursor(8, 1);
lcd_1.print(iAge);
delay(1000);
Gender();
return iAge;
}
int Gender() {
class String iGender;
lcd_1.clear();
lcd_1.print("Choose Gender:");
delay(100);
lcd_1.setCursor(0, 1);
lcd_1.print("*=Male #=Female");
delay(500);
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Choose Gender:");
lcd_1.setCursor(4, 1);
char Key = NO_KEY;
while (Key == NO_KEY) {
Key = customKeypad.getKey();
if (Key == '*') iGender == "Male";
else if (Key =='#') iGender == "Female";
else Key = NO_KEY;
}
Serial.print(Key);
lcd_1.print(Key);
Key = NO_KEY;
while (Key == NO_KEY) {
Key = customKeypad.getKey();
if (Key == '*') iGender = "Male";
else if (Key == '#') iGender = "Female";
else Key = NO_KEY;
}
Serial.print(Key);
lcd_1.println(Key);
lcd_1.clear();
lcd_1.setCursor(1, 0);
lcd_1.print("Your are a ");
lcd_1.setCursor(8, 1);
lcd_1.print(iGender);
delay(1000);
Receipt();
//return iGender;
// Height();
}
int Receipt() {
class String iReceipt;
lcd_1.clear();
lcd_1.print("Print Receipt ?");
delay(100);
lcd_1.setCursor(0, 1);
lcd_1.print("*=Yes #=No");
delay(500);
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("Print Receipt ?");
lcd_1.setCursor(4, 1);
char Key = NO_KEY;
while (Key == NO_KEY) {
Key = customKeypad.getKey();
if (Key == '*') iReceipt == "Print Receipt";
else if (Key =='#') iReceipt == "Not to Print Receipt";
else Key = NO_KEY;
}
Serial.print(Key);
lcd_1.print(Key);
Key = NO_KEY;
while (Key == NO_KEY) {
Key = customKeypad.getKey();
if (Key == '*') iReceipt = "Print a Receipt";
else if (Key == '#') iReceipt = "Not to Print ";
else Key = NO_KEY;
}
Serial.print(Key);
lcd_1.println(Key);
lcd_1.clear();
lcd_1.setCursor(1, 0);
lcd_1.print("You choosed ");
lcd_1.setCursor(0, 1);
lcd_1.print(iReceipt);
delay(1000);
Height();
delay(3000);
lcd_1.clear();
lcd_1.setCursor(4, 1);
lcd_1.print("Thank You");
delay(1000);
lcd_1.clear();
displayscreen();
//return iReceipt;
// Height();
}