#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
// Pin definitions for the TFT display
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
// Pin definition for the potentiometer
#define POT_PIN 34
// Create an instance of the display
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
// Initialize the serial monitor for debugging
Serial.begin(115200);
// Initialize the display
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
// Initialize the potentiometer pin
pinMode(POT_PIN, INPUT);
}
void loop() {
// Read the value from the potentiometer
int potValue = analogRead(POT_PIN);
// Map the potentiometer value (0-4095) to the display width
int barWidth = map(potValue, 0, 4095, 0, tft.width());
// Clear the display
tft.fillScreen(ILI9341_BLACK);
// Draw the bar graph
tft.fillRect(0, tft.height()/2 - 10, barWidth, 20, ILI9341_GREEN);
// Display the potentiometer value as text
tft.setCursor(10, 10);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Pot Value: ");
tft.println(potValue);
// Add a small delay
delay(100);
}