تعلم برمجة الاردوينو(المحركات والحساسات)programing motor,sensors with aurdoino motor shild

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ธ.ค. 2024

ความคิดเห็น • 3

  • @Icdhdgvfdjhf
    @Icdhdgvfdjhf 2 หลายเดือนก่อน +1

    ستمر

  • @opAAlz-kali
    @opAAlz-kali  2 หลายเดือนก่อน +3

    //import your motor shield library
    #include
    // set up motors.
    AF_DCMotor motor1(1, MOTOR12_1KHZ);
    AF_DCMotor motor2(2, MOTOR12_1KHZ);
    // define the pins of your sensor
    #define right_sensor_pin A0
    #define left_sensor_pin A1
    // sets speed of DC motors, between 0-255
    #define MOTOR_SPEED 150
    void setup() {
    // begin serial communication
    Serial.begin(9600);
    pinMode(left_sensor_pin, INPUT); // set the left_sensor pin to input
    pinMode(right_sensor_pin, INPUT); // set the right_sensor pin to input
    //set the speed of the motors
    motor1.setSpeed(MOTOR_SPEED);
    motor2.setSpeed (MOTOR_SPEED);

    }

    void loop() {
    int left_sensor = analogRead(left_sensor_pin);
    int right_sensor = analogRead(right_sensor_pin);
    Serial.print ("left : " );
    Serial.println (left_sensor );
    Serial.print ("right : " );
    Serial.println (right_sensor );
    if ( left_sensor 36) { // Black line delected by both sensors
    //turn right
    Serial.println ("Black line delected by both sensors" );
    moveStop();
    }
    }
    //Move forward Function
    void moveForward() {

    motor1.run(FORWARD);
    motor1.setSpeed(MOTOR_SPEED);
    motor2.run(FORWARD);
    motor2.setSpeed(MOTOR_SPEED);

    }
    //release movment Function
    void moveStop() {
    motor1.run(RELEASE);
    motor2.run(RELEASE);

    }

    //Turn Right Function
    void turnRight() {

    motor1.run(FORWARD);
    motor1.setSpeed(MOTOR_SPEED+50);
    motor2.run(BACKWARD);
    motor2.setSpeed(MOTOR_SPEED+50);

    }
    //Turn Left Function
    void turnLeft() {
    motor1.run(BACKWARD);
    motor1.setSpeed(MOTOR_SPEED+50);
    motor2.run(FORWARD);
    motor2.setSpeed(MOTOR_SPEED+50);

    }

  • @Icdhdgvfdjhf
    @Icdhdgvfdjhf 2 หลายเดือนก่อน +1

    انت قوي