#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include<SPI.h>
#define TFT_CS 15
#define TFT_RST 22
#define TFT_DC 2
#define SWITCH_PIN 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
int currentBox = 0;
bool switchPressed = false;
void setup() {
// Initialize the TFT display
tft.begin();
tft.setRotation(0); // Set rotation to portrait mode
tft.fillScreen(ILI9341_BLACK);
// Draw four vertical boxes
drawBoxes();
// Initialize switch pin
pinMode(SWITCH_PIN, INPUT_PULLUP);
// Highlight the first box
highlightBox(currentBox);
}
void drawBoxes() {
int boxWidth = tft.width() / 4;
for (int i = 0; i < 4; i++) {
tft.drawRect(i * boxWidth, 0, boxWidth, tft.height(), ILI9341_WHITE);
}
}
void highlightBox(int box) {
int boxWidth = tft.width() / 4;
tft.fillRect(box * boxWidth, 0, boxWidth, tft.height(), ILI9341_BLUE);
}
void moveCursor() {
// Clear previous box
int boxWidth = tft.width() / 4;
tft.fillRect(currentBox * boxWidth, 0, boxWidth, tft.height(), ILI9341_BLACK);
// Move to the next box
currentBox = (currentBox + 1) % 4;
// Highlight the new box
highlightBox(currentBox);
}
void loop() {
if (digitalRead(SWITCH_PIN) == LOW && !switchPressed) {
delay(200); // Debounce delay
switchPressed = true;
moveCursor();
} else if (digitalRead(SWITCH_PIN) == HIGH) {
switchPressed = false;
}
}