#define R1PWM 5
#define L1PWM 6
#define R1EN 7
#define L1EN 8
#define R2PWM 9
#define L2PWM 10
#define R2EN 11
#define L2EN 12
#define ILERI 1
#define GERI 0
#define sensor 2
#define sensorarka 3
int pot1, hiz;
bool yon;
void setup() {
Serial.begin(9600);
pinMode(R1PWM, OUTPUT);
pinMode(L1PWM, OUTPUT);
pinMode(L1EN, OUTPUT);
pinMode(R1EN, OUTPUT);
digitalWrite(R1EN, HIGH);
digitalWrite(L1EN, HIGH);
Serial.begin(9600);
pinMode(R2PWM, OUTPUT);
pinMode(L2PWM, OUTPUT);
pinMode(L2EN, OUTPUT);
pinMode(R2EN, OUTPUT);
digitalWrite(R2EN, HIGH);
digitalWrite(L2EN, HIGH);
pinMode(sensor, INPUT);
pinMode(sensorarka, INPUT);
}
void loop() {
pot1 = analogRead(A0);
hiz = map(pot1, 0, 1023, 0, 255);
if (digitalRead(sensor) && !digitalRead(sensorarka))
yon = motor_sur(ILERI);
if (!digitalRead(sensor) && digitalRead(sensorarka))
yon = motor_sur(GERI);
if (!digitalRead(sensor) && digitalRead(sensorarka))
yon = motor_sur(yon);
}
bool motor_sur(bool myon){
if(myon){
analogWrite(R1PWM, hiz);
digitalWrite(L1PWM, LOW);
digitalWrite(R2PWM, LOW);
analogWrite(L2PWM, hiz);
}
else{
analogWrite(L1PWM, hiz);
digitalWrite(R1PWM, LOW);
analogWrite(R2PWM, hiz);
digitalWrite(L2PWM, LOW);
}
return !myon;
}