#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_DC 2
#define TFT_CS 15
#define TFT_RST 4
#define BUTTON_PIN 13
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
bool layarNyala = false;
bool lastButtonState = HIGH;
// ===== LOGO KACANG =====
void gambarKacang(int x, int y) {
tft.fillCircle(x, y, 20, ILI9341_YELLOW);
tft.fillCircle(x + 15, y, 20, ILI9341_YELLOW);
}
// ===== WELCOME =====
void tampilWelcome() {
tft.fillScreen(ILI9341_BLACK);
// logo tengah
gambarKacang(140, 90);
// tulisan Welcome
tft.setCursor(90, 150);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Welcome");
}
// ===== DESKTOP =====
void tampilDesktop() {
tft.fillScreen(ILI9341_CYAN);
// judul OS
tft.setCursor(10, 10);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.print("PE OS");
// ===== ICON =====
tft.fillRect(20, 40, 40, 40, ILI9341_WHITE);
tft.drawRect(20, 40, 40, 40, ILI9341_BLACK);
tft.setCursor(22, 85);
tft.setTextSize(1);
tft.print("Browser");
tft.fillRect(80, 40, 40, 40, ILI9341_YELLOW);
tft.drawRect(80, 40, 40, 40, ILI9341_BLACK);
tft.setCursor(90, 85);
tft.print("File");
tft.fillRect(140, 40, 40, 40, ILI9341_MAGENTA);
tft.drawRect(140, 40, 40, 40, ILI9341_BLACK);
tft.setCursor(142, 85);
tft.print("Music");
tft.fillRect(200, 40, 40, 40, ILI9341_GREEN);
tft.drawRect(200, 40, 40, 40, ILI9341_BLACK);
tft.setCursor(205, 85);
tft.print("Game");
// window tengah
tft.fillRect(60, 110, 200, 80, ILI9341_WHITE);
tft.drawRect(60, 110, 200, 80, ILI9341_BLACK);
tft.setCursor(70, 140);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.print("Welcome PE OS!");
// taskbar
tft.fillRect(0, 200, 320, 40, ILI9341_DARKGREY);
tft.fillRect(0, 200, 60, 40, ILI9341_GREEN);
tft.setCursor(5, 210);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(2);
tft.print("Start");
tft.setCursor(250, 210);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("09:00");
}
void setup() {
SPI.begin(18, 19, 23);
tft.begin();
pinMode(BUTTON_PIN, INPUT_PULLUP);
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
bool buttonState = digitalRead(BUTTON_PIN);
if (lastButtonState == HIGH && buttonState == LOW) {
layarNyala = !layarNyala;
if (layarNyala) {
// ===== BOOT =====
tft.fillScreen(ILI9341_BLUE);
gambarKacang(140, 90);
tft.setCursor(60, 160);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Booting PE OS...");
delay(1500);
// ===== WELCOME =====
tampilWelcome();
delay(1500);
// ===== DESKTOP =====
tampilDesktop();
} else {
tft.fillScreen(ILI9341_BLACK);
}
delay(200);
}
lastButtonState = buttonState;
}Loading
ili9341-cap-touch
ili9341-cap-touch