// #include <Adafruit_GFX.h>
// #include <Adafruit_ILI9341.h>
// // Pin yang digunakan untuk layar ILI9341
// #define TFT_CS 10
// #define TFT_DC 9
// #define TFT_RST 8 // Gunakan -1 jika tidak menggunakan pin reset
// #define SOUND
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// void setup() {
// tft.begin();
// tft.setRotation(1); // Atur orientasi layar (1 = landscape, 0 = portrait)
// tft.fillScreen(ILI9341_BLACK); // Layar awal hitam
// tft.setTextColor(ILI9341_WHITE); // Teks berwarna putih
// tft.setTextSize(3); // Ukuran teks
// }
// void loop() {
// // Generate warna acak untuk latar belakang
// uint16_t bgColor = random(0xFFFF);
// // Bersihkan layar dengan warna latar belakang baru
// tft.fillScreen(bgColor);
// //Atur posisi teks
// int16_t x = (tft.width() - 60) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
// int16_t y = (tft.height() - 48) / 2; // Hitung posisi tengah vertikal (48 = perkiraan tinggi teks)
// int16_t x2 = (tft.width() - 60) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
// int16_t y2 = (tft.height() - 48) / 2;
// // Tampilkan teks "TEST"
// int16_t x3 = (tft.width() - 40) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
// int16_t y3 = (tft.height() - 48) / 2;
// int16_t x4 = (tft.width() -160) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
// int16_t y4 = (tft.height() - 48) / 2;
// int16_t x5 = (tft.width() - 30) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
// int16_t y5 = (tft.height() - 28) / 2;
// int16_t x6 = (tft.width() - 10) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
// int16_t y6 = (tft.height() - 14) / 2;
// //tampilan
// tft.setCursor(x, y);
// tft.print("selamat");
// tft.fillScreen(bgColor);
// tft.setCursor(x2, y2);
// tft.print("datang");
// tft.fillScreen(bgColor);
// tft.setCursor(x3, y3);
// tft.print("di");
// tft.fillScreen(bgColor);
// tft.setCursor(x4, y4);
// tft.print("supermarket");
// // tft.fillScreen(bgColor);
// // tft.setCursor(x5, y5);
// // tft.print("acumulaka");
// // tft.fillScreen(bgColor);
// // tft.setCursor(x6, y6);
// // tft.print("apel dan alat");
// delay(500); // Ganti warna setiap 1 detik
// }
// #include <Adafruit_GFX.h>
// #include <Adafruit_ILI9341.h>
// // Pin yang digunakan untuk layar ILI9341
// #define TFT_CS 10
// #define TFT_DC 9
// #define TFT_RST 8 // Gunakan -1 jika tidak menggunakan pin reset
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// // Array teks yang akan ditampilkan
// const char* texts[] = {"selamat", "datang", "text 2", "text 3", "text 4", "text 5"};
// int numTexts = sizeof(texts) / sizeof(texts[0]);
// void setup() {
// tft.begin();
// tft.setRotation(1); // Atur orientasi layar (1 = landscape, 0 = portrait)
// tft.fillScreen(ILI9341_BLACK); // Bersihkan layar dengan warna hitam
// tft.setTextColor(ILI9341_WHITE); // Teks berwarna putih
// tft.setTextSize(3); // Ukuran teks
// }
// void loop() {
// for (int i = 0; i < numTexts; i++) {
// // Generate warna acak untuk latar belakang
// uint16_t bgColor = random(0xFFFF);
// // Bersihkan layar dengan warna latar belakang baru
// tft.fillScreen(bgColor);
// // Hitung posisi teks agar berada di tengah layar
// int16_t x = (tft.width() - tft.textWidth(texts[i])) / 2;
// int16_t y = (tft.height() - (tft.textSize() * 8)) / 2; // textSize * 8 = tinggi teks
// // Tampilkan teks di posisi tengah
// tft.setCursor(x, y);
// tft.print(texts[i]);
// delay(1000); // Tampilkan teks selama 1 detik
// }
// }
// #include <Adafruit_GFX.h>
// #include <Adafruit_ILI9341.h>
// // Pin yang digunakan untuk layar ILI9341
// #define TFT_CS 10
// #define TFT_DC 9
// #define TFT_RST 8 // Gunakan -1 jika tidak menggunakan pin reset
// // Pin untuk sensor suara
// #define SOUND_SENSOR_PIN 3 // Sensor suara terhubung ke pin digital D3
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// void setup() {
// tft.begin();
// tft.setRotation(1); // Atur orientasi layar (1 = landscape, 0 = portrait)
// tft.fillScreen(ILI9341_BLACK); // Layar awal hitam
// tft.setTextColor(ILI9341_WHITE); // Teks berwarna putih
// tft.setTextSize(3); // Ukuran teks
// pinMode(SOUND_SENSOR_PIN, INPUT); // Atur pin sensor suara sebagai input
// }
// void loop() {
// // Baca nilai dari sensor suara
// int soundDetected = digitalRead(SOUND_SENSOR_PIN);
// if (soundDetected == HIGH) { // Jika suara terdeteksi
// // Generate warna acak untuk latar belakang
// uint16_t bgColor = random(0xFFFF);
// // Bersihkan layar dengan warna latar belakang baru
// tft.fillScreen(bgColor);
// // Atur posisi teks
// int16_t x = (tft.width() - 60) / 2; // Hitung posisi tengah horizontal
// int16_t y = (tft.height() - 48) / 2; // Hitung posisi tengah vertikal
// int16_t x2 = (tft.width() - 60) / 2;
// int16_t y2 = (tft.height() - 48) / 2;
// int16_t x3 = (tft.width() - 40) / 2;
// int16_t y3 = (tft.height() - 48) / 2;
// int16_t x4 = (tft.width() - 160) / 2;
// int16_t y4 = (tft.height() - 48) / 2;
// // Tampilkan teks
// tft.setCursor(x, y);
// tft.print("selamat");
// tft.fillScreen(bgColor);
// tft.setCursor(x2, y2);
// tft.print("datang");
// tft.fillScreen(bgColor);
// tft.setCursor(x3, y3);
// tft.print("di");
// tft.fillScreen(bgColor);
// tft.setCursor(x4, y4);
// tft.print("supermarket");
// delay(500); // Ganti warna setiap 500 ms
// } else {
// // Jika tidak ada suara, tetap layar hitam
// tft.fillScreen(ILI9341_BLACK);
// }
// }
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Pin yang digunakan untuk layar ILI9341
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8 // Gunakan -1 jika tidak menggunakan pin reset
// Pin untuk Sensor Ultrasonik
#define TRIGPIN 6 // Pin untuk Trigger sensor Ultrasonik
#define ECHOPIN 7 // Pin untuk Echo sensor Ultrasonik
// Pin untuk Buzzer
#define BUZZERPIN 5 // Pin untuk Buzzer
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.begin();
tft.setRotation(1); // Atur orientasi layar (1 = landscape, 0 = portrait)
tft.fillScreen(ILI9341_BLACK); // Layar awal hitam
tft.setTextColor(ILI9341_WHITE); // Teks berwarna putih
tft.setTextSize(3); // Ukuran teks
// Setup pin untuk Ultrasonik dan Buzzer
pinMode(TRIGPIN, OUTPUT);
pinMode(ECHOPIN, INPUT);
pinMode(BUZZERPIN, OUTPUT);
}
void loop() {
// Generate warna acak untuk latar belakang
uint16_t bgColor = random(0xFFFF);
// Bersihkan layar dengan warna latar belakang baru
tft.fillScreen(bgColor);
// Atur posisi teks
int16_t x = (tft.width() - 60) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
int16_t y = (tft.height() - 48) / 2; // Hitung posisi tengah vertikal (48 = perkiraan tinggi teks)
int16_t x2 = (tft.width() - 60) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
int16_t y2 = (tft.height() - 48) / 2;
int16_t x3 = (tft.width() - 40) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
int16_t y3 = (tft.height() - 48) / 2;
int16_t x4 = (tft.width() - 160) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
int16_t y4 = (tft.height() - 48) / 2;
int16_t x5 = (tft.width() - 30) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
int16_t y5 = (tft.height() - 28) / 2;
int16_t x6 = (tft.width() - 10) / 2; // Hitung posisi tengah horizontal (60 = perkiraan lebar teks)
int16_t y6 = (tft.height() - 14) / 2;
// Tampilan teks
tft.setCursor(x, y);
tft.print("selamat");
tft.fillScreen(bgColor);
tft.setCursor(x2, y2);
tft.print("datang");
tft.fillScreen(bgColor);
tft.setCursor(x3, y3);
tft.print("di");
tft.fillScreen(bgColor);
tft.setCursor(x4, y4);
tft.print("supermarket");
tft.fillScreen(bgColor);
// tft.setCursor(x5, y5);
// tft.print("acumulaka");
// tft.fillScreen(bgColor);
// tft.setCursor(x6, y6);
// tft.print("apel dan alat");
// Mengukur jarak menggunakan sensor Ultrasonik
long jarak = getDistance();
// Jika jarak < 20 cm, aktifkan buzzer
if (jarak < 20) {
tone(BUZZERPIN, 1000); // Buzzer berbunyi pada frekuensi 1000 Hz
} else {
noTone(BUZZERPIN); // Matikan buzzer
}
delay(500); // Ganti warna setiap 1 detik
}
// Fungsi untuk mengukur jarak menggunakan sensor Ultrasonik
long getDistance() {
// Kirim pulsa trigger
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
// Menghitung waktu yang dibutuhkan untuk mendapatkan pantulan echo
long durasi = pulseIn(ECHOPIN, 1000);
// Hitung jarak berdasarkan waktu yang ditempuh oleh gelombang suara
long jarak = durasi * 0.034 / 2; // Kecepatan suara 0.034 cm/us, dibagi 2 karena perjalanan pergi-pulang
return jarak;
}