#include <SPI.h>
#include <Adafruit_ILI9341.h>
// Initialize the IL19341 display
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Initialize the buzzer pin
int buzzerPin = 3;
void setup() {
// Set the button pins as inputs with pull-up resistors
pinMode(2, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
// Initialize the IL19341 display
tft.begin();
tft.setRotation(3);
// Print a message to the IL19341 display
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.println("Arduino Project");
}
void loop() {
// Read the values from the potentiometer and buttons
int potValue = analogRead(A0);
int button1 = digitalRead(2);
int button2 = digitalRead(4);
// Check if the potentiometer has changed
static int lastPotValue = -1;
if (potValue != lastPotValue) {
// Clear the old value from the display
tft.fillRect(0, 70, 240, 20, ILI9341_BLACK);
// Print the new value to the display
tft.setCursor(0, 70);
tft.print("Pot: ");
tft.print(potValue);
// Update the last potentiometer value
lastPotValue = potValue;
}
// Check if button 1 is pressed
if (button1 == LOW) {
// Clear the old value from the display
tft.fillRect(0, 30, 240, 20, ILI9341_BLACK);
// Print the new value to the display
tft.setCursor(0, 30);
tft.print("Button 1: ");
tft.print(button1);
// Play a tone on the buzzer
tone(buzzerPin, 1000, 500); // Play a 1kHz tone for 500 milliseconds
delay(500); // Wait for the tone to finish playing
noTone(buzzerPin); // Stop the tone
}
// Check if button 2 is pressed
if (button2 == LOW) {
// Clear the old value from the display
tft.fillRect(0, 50, 240, 20, ILI9341_BLACK);
// Print the new value to the display
tft.setCursor(0, 50);
tft.print("Button 2: ");
tft.print(button2);
}
// Wait a short amount of time to avoid overwhelming the display
delay(100);
}