#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Servo.h>
// منافذ الشاشة (لا تغيرها)
#define TFT_SCK 3
#define TFT_MOSI 4
#define TFT_DC 6
#define TFT_CS 9
#define TFT_RST 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_RST);
// --- المنافذ الجديدة (A0, A1, A2) ---
const int servoPin = A0;
const int trigPin = A1;
const int echoPin = A2;
Servo myServo;
void setup() {
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
myServo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setCursor(20, 20);
tft.print("HARDWARE CHECK...");
}
void loop() {
for (int i = 15; i <= 165; i += 5) {
testSystem(i);
}
}
void testSystem(int angle) {
myServo.write(angle); // تحريك السيرفو
// قياس المسافة
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH, 30000);
int distance = duration * 0.034 / 2;
// عرض البيانات على الشاشة للتأكد
tft.fillRect(20, 60, 280, 100, ILI9341_BLACK); // مسح المنطقة
tft.setCursor(20, 80);
tft.setTextColor(ILI9341_GREEN);
tft.print("Angle: "); tft.print(angle);
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.print("Distance: "); tft.print(distance); tft.print(" cm");
delay(100);
}
4
2March 19, 2026 2.4K 11