• Serial
  • Serial.print(i); // The current degree is sent to the Serial Port. Serial




    Download 0,69 Mb.
    bet3/3
    Sana16.11.2023
    Hajmi0,69 Mb.
    #99956
    1   2   3
    Bog'liq
    5 ish o`rnatilgan

    Serial.print(i); // The current degree is sent to the Serial Port.
    Serial.print(","); // Addition character is sent right next to the previous value, which is required for indexing later in the Processing IDE.
    Serial.print(distance); // The value of the distance is sent to the Serial Port.
    Serial.print("."); // Addition character is sent right next to the previous value, which is required for indexing later in the Processing IDE.
    }
    // Repeats the previous lines from 180 to 0 degrees
    for(int i=180;i>0;i--){
    myServo.write(i);
    delay(30);
    distance = calculateDistance();
    Serial.print(i);
    Serial.print(",");
    Serial.print(distance);
    Serial.print(".");
    }
    }
    // The distance measured by the Ultrasonic sensor is calculated using this function.
    int calculateDistance(){
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // For 10 microseconds, the trigPin is in the HIGH state.
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH); // Returns the sound wave travel time in microseconds after reading the echoPin.
    distance= duration*0.034/2;
    return distance;
    }

    Linki



    https://wokwi.com/projects/365677070549587969
    Download 0,69 Mb.
    1   2   3




    Download 0,69 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Serial.print(i); // The current degree is sent to the Serial Port. Serial

    Download 0,69 Mb.