/*
This is the code written for wokwi simulation of
the Automatic Drug Dispensing Device project by Yusuf Musa Saleh
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
// include the library code:
#include <LiquidCrystal.h>
#include <Keypad.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // lcd object created
const char number_of_rows = 4; // number of rows in the keypad
const char number_of_columns = 4; //number of columns in the keypad
byte row_pins[number_of_rows] = {A0,A1,A2,A3}; // setting up the array of rows
byte column_pins[number_of_columns] = {A4,A5,13,12}; // setting up the array of columns
char key_array[number_of_rows][number_of_columns] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
//Declaring keypad object
Keypad k = Keypad(makeKeymap(key_array),row_pins,column_pins,number_of_rows,number_of_columns);
//Function prototypes
void welcomePage(); //This displays the welcome message of the device
void EnterDrugName(); //This function is where we will enter the name of our drug
void PullUps(); //This pull up is used to enable the use of analog pins as digital pins
void setup()
{
//Any function in the setup will be ran once
PullUps();
welcomePage();
EnterDrugName();
}
void loop()
{
//our void loop is empty
}
void welcomePage()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Welcome");
delay(3000);
lcd.setCursor(0, 0);
lcd.print("Automatic Drug");
lcd.setCursor(0, 1);
lcd.print("Dispensing");
delay(3000);
lcd.clear();
//delay(3000);
lcd.setCursor(0, 0);
lcd.print("By Brail Vision");
delay(3000);
lcd.setCursor(0, 0);
lcd.print("Enter Drug Name");
delay(3000);
lcd.clear();
}
void EnterDrugName()
{
char drug_key[3] = {'\0', '\0','\0'}; // Initialize empty keys
int key_count = 0;
lcd.setCursor(0, 0);
lcd.print("Drug1");
lcd.setCursor(8, 0);
while (key_count < 3)
{
char key = k.getKey();
if (key != NO_KEY)
{ // Check if a key is actually pressed
drug_key[key_count] = key;
lcd.print(drug_key[key_count]);
delay(1000);
key_count++;
delay(200); // Small delay to prevent rapid multiple key detections
}
}
key_count = 0; //reset the counter to zero before calling it for the second time
lcd.setCursor(0, 1);
lcd.print("Drug2");
lcd.setCursor(8, 1);
while (key_count < 3)
{
char key = k.getKey();
if (key != NO_KEY)
{ // Check if a key is actually pressed
drug_key[key_count] = key;
lcd.print(drug_key[key_count]);
delay(1000);
key_count++;
delay(200); // Small delay to prevent rapid multiple key detections
}
}
//delay(3000);
}
void PullUps()
{
//pins A0 to A5 are connected to the keypad as input pins of the
//microcontroller
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A5, INPUT_PULLUP);
}