100% found this document useful (1 vote)
31 views4 pages

FPT (Vending Machine)

This document contains an Arduino sketch for a keypad and LCD interface that allows users to input a code to retrieve prices for apples and oranges. The program initializes the keypad and LCD, displays a welcome message, and processes user input to show the corresponding prices and a payment prompt. After displaying the information, it resets to allow for new inputs.

Uploaded by

studies.diya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
31 views4 pages

FPT (Vending Machine)

This document contains an Arduino sketch for a keypad and LCD interface that allows users to input a code to retrieve prices for apples and oranges. The program initializes the keypad and LCD, displays a welcome message, and processes user input to show the corresponding prices and a payment prompt. After displaying the information, it resets to allow for new inputs.

Uploaded by

studies.diya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Import the libraries

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Configure the keypad


const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = { // Assign ASCII characters to keys


{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};

byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

String outputString1 = ""; // To store the output string


String outputString2 = ""; // To store the output string
String code = ""; // Variable for code

// make a function to clear the LCD screen


void clear() {

outputString1 = " "; // To clear the first line of the LCD


outputString2 = " "; // To clear the first line of the LCD

lcd.setCursor(0, 0);
lcd.print(outputString1);
lcd.setCursor(0, 1);
lcd.print(outputString2);
}

void setup() {
lcd.init(); // Initialize the LCD screen
lcd.backlight();
lcd.clear(); // Clear the LCD screen
Serial.begin(9600); // Set the serial baud rate
}
void loop() {
//Loop for when the code is empty so that the function runs over again
if (code == "") {

String outputString1 = "Welcome!Apples:9"; // Set the output


String outputString2 = "Oranges: C"; // Set the output

//Print the output

lcd.setCursor(0, 0);
lcd.print(outputString1);
lcd.setCursor(0, 1);
lcd.print(outputString2);

//clear the LCD after 2 seconds


delay(2000);
clear();

outputString1 = "Enter Code"; // Set the output

// Get the user’s input for the code


char customKey = customKeypad.getKey();

if (customKey) {
Serial.println(customKey);

// Append the key to output variable and the code variable


code = customKey;
inputString2 = customKey;

lcd.setCursor(0, 1);
lcd.print(code);
}
}

// Condition statement for if the code is 9 - Apples

if (code == "9") {

// Set the output and then print it

outputString1 = "The cost for";


outputString2 = "Apples is $3";

lcd.setCursor(0, 0);
lcd.print(outputString1);
lcd.setCursor(0, 1);
lcd.print(outputString2);

// Clear the screen after 2 seconds


delay(2000);
clear();

// Set the output and then print it

outputString1 = "Pay by pressing";


outputString2 = "the button";

lcd.setCursor(0, 0);
lcd.print(outputString1);
lcd.setCursor(0, 1);
lcd.print(outputString2);
// Clear the screen after 3 seconds
delay(3000);
clear();

//Print thank you

inputString1 = "Thank you";


lcd.setCursor(0, 0);
lcd.print(outputString1);

delay(3000);

// Reset the code so it loops back to the beginning

code = "";
}

// Condition statement for if the code is C - Oranges

if (code == "C") {

// Set the output and then print it


outputString1 = "The cost for";
outputString2 = "Oranges is $4";

lcd.setCursor(0, 0);
lcd.print(outputString1);
lcd.setCursor(0, 1);
lcd.print(outputString2);

// Clear the screen after 2 seconds

delay(2000);
clear();
// Set the output and then print it
outputString1 = "Pay by pressing";
outputString2 = "the button";

lcd.setCursor(0, 0);
lcd.print(outputString1);
lcd.setCursor(0, 1);
lcd.print(outputString2);

// Clear the screen after 3 seconds


delay(3000);
clear();

//Print thank you

outputString1 = "Thank you";


lcd.setCursor(0, 0);
lcd.print(outputString1);

delay(3000);

// Reset the code so it loops back to the beginning

code = "";
}
}

You might also like