// Include the necessary libraries
#include <LiquidCrystal.h>
// Define the LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define the button pins
const int addButtonPin = 6;
const int subtractButtonPin = 7;
const int multiplyButtonPin = 8;
const int divideButtonPin = 9;
// Define the potentiometer pins
const int firstNumberPotPin = A0;
const int secondNumberPotPin = A1;
// Variables to store the numbers and result
float firstNumber = 0;
float secondNumber = 0;
float result = 0;
// Variables to store the button states
int addButtonState = 0;
int subtractButtonState = 0;
int multiplyButtonState = 0;
int divideButtonState = 0;
void setup() {
// Set up the LCD
lcd.begin(16, 2);
// Set up the button pins as inputs
pinMode(addButtonPin, INPUT);
pinMode(subtractButtonPin, INPUT);
pinMode(multiplyButtonPin, INPUT);
pinMode(divideButtonPin, INPUT);
// Set up the potentiometer pins as inputs
pinMode(firstNumberPotPin, INPUT);
pinMode(secondNumberPotPin, INPUT);
}
void loop() {
// Read the button states
addButtonState = digitalRead(addButtonPin);
subtractButtonState = digitalRead(subtractButtonPin);
multiplyButtonState = digitalRead(multiplyButtonPin);
divideButtonState = digitalRead(divideButtonPin);
// Read the potentiometer values
firstNumber = analogRead(firstNumberPotPin);
secondNumber = analogRead(secondNumberPotPin);
// Convert the potentiometer values to numbers between 0 and 100
firstNumber = map(firstNumber, 0, 1023, 0, 100);
secondNumber = map(secondNumber, 0, 1023, 0, 100);
// Perform the calculation based on the button pressed
if (addButtonState == HIGH) {
result = firstNumber + secondNumber;
} else if (subtractButtonState == HIGH) {
result = firstNumber - secondNumber;
} else if (multiplyButtonState == HIGH) {
result = firstNumber * secondNumber;
} else if (divideButtonState == HIGH) {
result = firstNumber / secondNumber;
}
// Display the result on the LCD
lcd.setCursor(0, 0);
lcd.print("Result: ");
lcd.setCursor(0, 1);
lcd.print(result);
// Delay for stability
delay(100);
}