const int potPin = A0; // مدخل المقاومة المتغيرة
const int in1 = 8; // IN1 من L293D
const int in2 = 7; // IN2 من L293D
const int enA = 9; // ENA للتحكم في السرعة (PWM)
void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enA, OUTPUT);
}
void loop() {
int potValue = analogRead(potPin); // قراءة المقاومة (0 - 1023)
int speed;
if (potValue <= 511) {
// مع عقارب الساعة
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
speed = map(potValue, 0, 511, 0, 255); // تحويل القيمة لسرعة PWM
} else {
// عكس عقارب الساعة
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
speed = map(potValue, 512, 1023, 0, 255);
}
analogWrite(enA, speed); // إرسال السرعة للموتور
delay(10); // تهدئة التحديث
}