#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <XPT2046_Touchscreen.h>
#include <SPI.h>
// Definisikan pin untuk LCD
#define TFT_CLK 18
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_CS 16
#define TFT_RST 4
#define TFT_DC 5
// Definisikan pin untuk touchscreen
#define TOUCH_CS 15
#define TOUCH_IRQ 21
// Inisialisasi objek untuk LCD dan touchscreen
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
XPT2046_Touchscreen ts(TOUCH_CS, TOUCH_IRQ);
void setup() {
Serial.begin(115200);
// Inisialisasi LCD
tft.begin();
tft.setRotation(1); // Atur rotasi jika diperlukan
tft.fillScreen(ILI9341_BLACK); // Bersihkan layar dengan warna hitam
// Tampilkan teks dasar pada LCD
tft.setTextColor(ILI9341_WHITE); // Set warna teks menjadi putih
tft.setTextSize(2); // Set ukuran teks
tft.setCursor(10, 20);
tft.println("SISTEM ANDON MAINTENANCE");
// Tampilkan "LINE 1"
tft.fillRect(10, 70, 120, 60, ILI9341_GREEN); // Background hijau
tft.setTextColor(ILI9341_BLACK); // Set warna teks menjadi hitam
tft.setCursor(35, 90);
tft.print("LINE 1");
// Tampilkan "LINE 2"
tft.fillRect(190, 70, 120, 60, ILI9341_GREEN); // Background hijau
tft.setTextColor(ILI9341_BLACK); // Set warna teks menjadi hitam
tft.setCursor(215, 90);
tft.print("LINE 2");
// TAMPILKAN "HISTORY"
tft.fillRect(190, 160, 120, 40, ILI9341_WHITE); // Background putih
tft.setTextColor(ILI9341_BLACK); // Set warna teks menjadi hitam
tft.setCursor(210, 175);
tft.print("HISTORY");
// Inisialisasi touchscreen
SPI.begin();
ts.begin();
ts.setRotation(1);
}
void showHistoryPage() {
// Tampilkan halaman "History"
tft.fillScreen(ILI9341_BLACK); // Bersihkan layar
tft.setTextColor(ILI9341_WHITE); // Set warna teks menjadi putih
tft.setTextSize(2);
tft.setCursor(10, 20);
tft.println("Rekap Masalah:");
tft.setCursor(10, 50);
tft.println("- Masalah 1");
tft.setCursor(10, 80);
tft.println("- Masalah 2");
tft.setCursor(10, 110);
tft.println("- Masalah 3");
// Tampilkan tombol "Kembali"
tft.fillRect(190, 200, 120, 40, ILI9341_RED); // Background merah
tft.setTextColor(ILI9341_WHITE); // Set warna teks menjadi putih
tft.setCursor(210, 215);
tft.print("KEMBALI");
}
void loop() {
// Cek sentuhan touchscreen
if (ts.touched()) {
TS_Point p = ts.getPoint();
// Map koordinat sentuhan ke ukuran layar LCD
int touchX = map(p.x, 0, 4095, 0, tft.width());
int touchY = map(p.y, 0, 4095, 0, tft.height());
// Cetak koordinat sentuhan ke Serial Monitor
Serial.print("X: ");
Serial.print(touchX);
Serial.print("\tY: ");
Serial.print(touchY);
Serial.print("\tPressure: ");
Serial.println(p.z);
// Deteksi jika tombol "History" ditekan
if (touchX > 190 && touchX < 310 && touchY > 160 && touchY < 200) {
showHistoryPage();
}
// Deteksi jika tombol "Kembali" ditekan
if (touchX > 190 && touchX < 310 && touchY > 200 && touchY < 240) {
setup(); // Kembali ke tampilan awal
}
}
delay(100); // Tunda sebentar sebelum membaca sentuhan berikutnya
}
Loading
ili9341-cap-touch
ili9341-cap-touch