#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_CS 15
#define TFT_RST 4
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_CLK 18
#define TFT_MISO 19
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
#define BUTTON_PIN 13
boolean tekan;
int cursorPos = 0;
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
tft.begin();
tft.setRotation(3); // Adjust the rotation as needed
tft.fillScreen(ILI9341_BLACK);
drawBoxes();
drawCursor(cursorPos);
}
void loop() {
tekan = digitalRead(BUTTON_PIN);
if (tekan == LOW) {
delay(100); // debounce delay
cursorPos = (cursorPos + 1) % 4;
drawBoxes();
drawCursor(cursorPos);
}
}
void drawBoxes() {
tft.fillScreen(ILI9341_BLACK);
// Draw boxes with options
tft.drawRect(0, 0, tft.width(), 60, ILI9341_WHITE);
tft.setCursor(10, 20);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Option 1");
tft.drawRect(0, 60, tft.width(), 60, ILI9341_WHITE);
tft.setCursor(10, 80);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Option 2");
tft.drawRect(0, 120, tft.width(), 60, ILI9341_WHITE);
tft.setCursor(10, 140);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Option 3");
tft.drawRect(0, 180, tft.width(), 60, ILI9341_WHITE);
tft.setCursor(10, 200);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Option 4");
}
void drawCursor(int boxIndex) {
int y = 0;
switch (boxIndex) {
case 0:
y = 0;
break;
case 1:
y = 60;
break;
case 2:
y = 120;
break;
case 3:
y = 180;
break;
}
tft.fillRect(0, y, tft.width(), 60, ILI9341_WHITE); // Highlight the selected box
// Redraw the option text in the highlighted box
tft.setCursor(10, y + 20);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
switch (boxIndex) {
case 0:
tft.print("Option 1");
break;
case 1:
tft.print("Option 2");
break;
case 2:
tft.print("Option 3");
break;
case 3:
tft.print("Option 4");
break;
}
}