Çizgi İzleyen Yol Seçme Yardım Lütfen
  • Merhaba,
    Bir çizgi izleyen kodum var ve bu robotun çift yol gördüğünde sırayla sağa ve sola dönmesini istiyorum nasıl yapabilirim?

    KOD;
    #include < xmotion.h>

    #define RightMotorDir 13
    #define RightMotorPwmPin 11
    #define LeftMotorDir 12
    #define LeftMotorPwmPin 3

    #define Led1 8
    #define Led2 9

    #define DipSwitch1 5
    #define DipSwitch2 6
    #define DipSwitch3 7

    #define Start 10


    #define s0 A2
    #define s1 A4
    #define s2 A5
    #define s3 4
    #define Sens A1


    int sensor15;//base

    int a;
    int ab;
    int sagdacizgivar;
    int soldacizgivar;


    void setup() {

    pinMode(DipSwitch1, INPUT);
    pinMode(DipSwitch2, INPUT);
    pinMode(DipSwitch3, INPUT);
    pinMode(Start, INPUT);

    digitalWrite(DipSwitch1, HIGH);
    digitalWrite(DipSwitch2, HIGH);
    digitalWrite(DipSwitch3, HIGH);


    pinMode(Led1, OUTPUT);
    pinMode(Led2, OUTPUT);
    pinMode(s0, OUTPUT);
    pinMode(s1, OUTPUT);
    pinMode(s2, OUTPUT);
    pinMode(s3, OUTPUT);
    digitalWrite(s0, LOW);
    digitalWrite(s1, LOW);
    digitalWrite(s2, LOW);
    digitalWrite(s3, LOW);

    delay(1000);

    pinMode(Sens,INPUT);
    pinMode(RightMotorDir, OUTPUT);
    pinMode(RightMotorPwmPin, OUTPUT);
    pinMode(LeftMotorDir, OUTPUT);
    pinMode(LeftMotorPwmPin, OUTPUT);

    //Serial.begin(9600);
    }

    void loop() {

    digitalWrite(s0, LOW);
    digitalWrite(s1, LOW);//motorcontrol 60,0
    digitalWrite(s2, LOW);//0
    digitalWrite(s3, LOW);
    if (analogRead(Sens) <= 300){<br /> a = 60;
    ab = -10;
    }

    digitalWrite(s0, HIGH);
    digitalWrite(s1, LOW);//1
    digitalWrite(s2, LOW);// motorcontrol 55,0
    digitalWrite(s3, LOW);
    if (analogRead(Sens) <= 300){<br /> a = 55;
    ab = -10;
    }
    digitalWrite(s0, LOW);
    digitalWrite(s1, HIGH);
    digitalWrite(s2, LOW);//2
    digitalWrite(s3, LOW);//motorcontrol 50,0
    if (analogRead(Sens) <= 300){<br /> a = 50;
    ab = -10;
    }


    digitalWrite(s0, HIGH);
    digitalWrite(s1, HIGH);//motorcontrol 35,0
    digitalWrite(s2, LOW);//3
    digitalWrite(s3, LOW);
    if (analogRead(Sens) <= 300){<br /> a = 40;
    ab = -10;
    }


    digitalWrite(s0, LOW);
    digitalWrite(s1, LOW);//4
    digitalWrite(s2, HIGH);//motorcontrol 35,10
    digitalWrite(s3, LOW);
    if (analogRead(Sens) <= 300){<br /> a = 35;
    ab = -5;
    }


    digitalWrite(s0, HIGH);//5
    digitalWrite(s1, LOW);//motorcontrol 30,10
    digitalWrite(s2, HIGH);
    digitalWrite(s3, LOW);
    if (analogRead(Sens) <= 300){<br /> a = 30;
    ab = -5;
    }


    digitalWrite(s0, LOW);
    digitalWrite(s1, HIGH);//6
    digitalWrite(s2, HIGH);//motorcontrol 30,30
    digitalWrite(s3, LOW);
    if (analogRead(Sens) <= 300){<br /> a = 50;
    ab = 20;
    }


    digitalWrite(s0, HIGH);
    digitalWrite(s1, HIGH);//7
    digitalWrite(s2, HIGH);//motorcontrol 40,40
    digitalWrite(s3, LOW);
    if (analogRead(Sens) <= 300){<br /> a = 50;
    ab = 50;
    }

    digitalWrite(s0, LOW);//8
    digitalWrite(s1, LOW);//motorcontrol 30,30
    digitalWrite(s2, LOW);
    digitalWrite(s3, HIGH);
    if (analogRead(Sens) <= 300){<br /> a = 20;
    ab = 50;
    }

    digitalWrite(s0, HIGH);
    digitalWrite(s1, LOW);//9
    digitalWrite(s2, LOW);//motorcontrol 10,30
    digitalWrite(s3, HIGH);
    if (analogRead(Sens) <= 300){<br /> a = -5;
    ab = 30;
    }

    digitalWrite(s0, LOW);
    digitalWrite(s1, HIGH);//10
    digitalWrite(s2, LOW);//motorcontrol 10,35
    digitalWrite(s3, HIGH);
    if (analogRead(Sens) <= 300){<br /> a = -5;
    ab = 35;
    }

    digitalWrite(s0, HIGH);//11
    digitalWrite(s1, HIGH);//motorcontrol 5,35
    digitalWrite(s2, LOW);
    digitalWrite(s3, HIGH);
    if (analogRead(Sens) <= 300){<br /> a = -10;
    ab = 40;
    }


    digitalWrite(s0, LOW);//12
    digitalWrite(s1, LOW);
    digitalWrite(s2, HIGH);//motorcontrol 0,50
    digitalWrite(s3, HIGH);
    if (analogRead(Sens) <= 300){<br /> a = -10;
    ab = 50;
    }


    digitalWrite(s0, HIGH);
    digitalWrite(s1, LOW);//13
    digitalWrite(s2, HIGH);//motorcontrol 0,55
    digitalWrite(s3, HIGH);
    if (analogRead(Sens) <= 300){<br /> a = -10;
    ab = 55;

    }

    digitalWrite(s0, LOW);
    digitalWrite(s1, HIGH);//motorcontrol 0,60
    digitalWrite(s2, HIGH);//14
    digitalWrite(s3, HIGH);
    if (analogRead(Sens) <= 300){<br /> a = -10;
    ab = 60;
    }



    xmotion.MotorControl(a,ab); // motorlara belirlenen hız değerleri uygulandı
    //Serial.println(sensor7);
    //Serial.println(Trimpot);
    //Serial.println(DipSwitch1);
    //Serial.println(analogRead(Sens));
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook
Açık kaynak kültürü gereği, çözdüğünüz problemlerin çözümlerini paylaşmayı lütfen unutmayın.