#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
void setup() {
// put your setup code here, to run once:
motor1.setSpeed(255); //1R MOTORIIN HURD
motor2.setSpeed(168); //2R MOTORIIN HURD
pinMode(A0, INPUT); // initialize Left sensor as an input
pinMode(A1, INPUT); // initialize Right sensor as an input
}
void loop() {
int LEFT_SENSOR = digitalRead(A0);
int RIGHT_SENSOR = digitalRead(A1);
if(RIGHT_SENSOR==0 && LEFT_SENSOR==0) { uragshaa();}
else if(RIGHT_SENSOR==0 && LEFT_SENSOR==1) {baruun(); //Move Right
}
else if(RIGHT_SENSOR==1 && LEFT_SENSOR==0) {zuun(); //Move Left
}
else if(RIGHT_SENSOR==1 && LEFT_SENSOR==1) {zogs(); //STOP
}
}
void uragshaa() {
motor1.run(FORWARD);
motor2.run(FORWARD);
}
void hoishoo() {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
}
void zogs() {
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void baruun() {
motor1.run(FORWARD);
motor2.run(RELEASE);
}
void zuun() {
motor1.run(RELEASE);
motor2.run(FORWARD);
}
No comments:
Post a Comment