Skip to content

Create Jordan #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Create Jordan #149

wants to merge 1 commit into from

Conversation

Eb171767
Copy link

#include <Servo.h>

const int trigPin = 9;
const int echoPin = 10;
const int motorLeft = 5;
const int motorRight = 6;

Servo servo;
int angleCenter = 90;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorLeft, OUTPUT);
pinMode(motorRight, OUTPUT);
Serial.begin(9600);
servo.attach(3);
servo.write(angleCenter);
}

long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
return pulseIn(echoPin, HIGH) * 0.034 / 2;
}

long getAverageDistance() {
long total = 0;
for (int i = 0; i < 5; i++) {
total += getDistance();
delay(10);
}
return total / 5;
}

int scanAngle(int angle) {
servo.write(angle);
delay(300);
return getAverageDistance();
}

void loop() {
long distance = getAverageDistance();
Serial.println(distance);

if (distance == 0 || distance > 300) {
digitalWrite(motorLeft, LOW);
digitalWrite(motorRight, LOW);
return;
}

if (distance < 20) {
// توقّف مؤقت
digitalWrite(motorLeft, LOW);
digitalWrite(motorRight, LOW);
delay(200);

// فحص الاتجاهات
int left = scanAngle(150);
int right = scanAngle(30);
servo.write(angleCenter);
delay(100);

if (left > right) {
  // انعطاف لليسار
  digitalWrite(motorLeft, HIGH);
  digitalWrite(motorRight, LOW);
} else {
  // انعطاف لليمين
  digitalWrite(motorLeft, LOW);
  digitalWrite(motorRight, HIGH);
}

delay(500);  // وقت الانعطاف

} else {
// حركة أمامية
digitalWrite(motorLeft, HIGH);
digitalWrite(motorRight, HIGH);
}

delay(50); // تخفيف الضغط على الحلقة
}

At the moment we are not accepting contributions to the repository.

#include <Servo.h>

const int trigPin = 9;
const int echoPin = 10;
const int motorLeft = 5;
const int motorRight = 6;

Servo servo;
int angleCenter = 90;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorLeft, OUTPUT);
  pinMode(motorRight, OUTPUT);
  Serial.begin(9600);
  servo.attach(3);
  servo.write(angleCenter);
}

long getDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  return pulseIn(echoPin, HIGH) * 0.034 / 2;
}

long getAverageDistance() {
  long total = 0;
  for (int i = 0; i < 5; i++) {
    total += getDistance();
    delay(10);
  }
  return total / 5;
}

int scanAngle(int angle) {
  servo.write(angle);
  delay(300);
  return getAverageDistance();
}

void loop() {
  long distance = getAverageDistance();
  Serial.println(distance);

  if (distance == 0 || distance > 300) {
    digitalWrite(motorLeft, LOW);
    digitalWrite(motorRight, LOW);
    return;
  }

  if (distance < 20) {
    // توقّف مؤقت
    digitalWrite(motorLeft, LOW);
    digitalWrite(motorRight, LOW);
    delay(200);

    // فحص الاتجاهات
    int left = scanAngle(150);
    int right = scanAngle(30);
    servo.write(angleCenter);
    delay(100);

    if (left > right) {
      // انعطاف لليسار
      digitalWrite(motorLeft, HIGH);
      digitalWrite(motorRight, LOW);
    } else {
      // انعطاف لليمين
      digitalWrite(motorLeft, LOW);
      digitalWrite(motorRight, HIGH);
    }

    delay(500);  // وقت الانعطاف
  } else {
    // حركة أمامية
    digitalWrite(motorLeft, HIGH);
    digitalWrite(motorRight, HIGH);
  }

  delay(50);  // تخفيف الضغط على الحلقة
}
Copy link

At the moment we are not accepting contributions to the repository.

Feedback for Copilot.vim can be given in the feedback forum.

@github-actions github-actions bot closed this Jul 23, 2025
@Eb171767
Copy link
Author

#include <Servo.h>

const int trigPin = 9;
const int echoPin = 10;
const int motorLeft = 5;
const int motorRight = 6;

Servo servo;
int angleCenter = 90;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorLeft, OUTPUT);
pinMode(motorRight, OUTPUT);
Serial.begin(9600);
servo.attach(3);
servo.write(angleCenter);
}

long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
return pulseIn(echoPin, HIGH) * 0.034 / 2;
}

long getAverageDistance() {
long total = 0;
for (int i = 0; i < 5; i++) {
total += getDistance();
delay(10);
}
return total / 5;
}

int scanAngle(int angle) {
servo.write(angle);
delay(300);
return getAverageDistance();
}

void loop() {
long distance = getAverageDistance();
Serial.println(distance);

if (distance == 0 || distance > 300) {
digitalWrite(motorLeft, LOW);
digitalWrite(motorRight, LOW);
return;
}

if (distance < 20) {
// توقّف مؤقت
digitalWrite(motorLeft, LOW);
digitalWrite(motorRight, LOW);
delay(200);

// فحص الاتجاهات
int left = scanAngle(150);
int right = scanAngle(30);
servo.write(angleCenter);
delay(100);

if (left > right) {
  // انعطاف لليسار
  digitalWrite(motorLeft, HIGH);
  digitalWrite(motorRight, LOW);
} else {
  // انعطاف لليمين
  digitalWrite(motorLeft, LOW);
  digitalWrite(motorRight, HIGH);
}

delay(500);  // وقت الانعطاف

} else {
// حركة أمامية
digitalWrite(motorLeft, HIGH);
digitalWrite(motorRight, HIGH);
}

delay(50); // تخفيف الضغط على الحلقة
}

@Eb171767
Copy link
Author

#include <Servo.h>

const int trigPin = 9;
const int echoPin = 10;
const int motorLeft = 5;
const int motorRight = 6;

Servo servo;
int angleCenter = 90;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorLeft, OUTPUT);
pinMode(motorRight, OUTPUT);
Serial.begin(9600);
servo.attach(3);
servo.write(angleCenter);
}

long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
return pulseIn(echoPin, HIGH) * 0.034 / 2;
}

long getAverageDistance() {
long total = 0;
for (int i = 0; i < 5; i++) {
total += getDistance();
delay(10);
}
return total / 5;
}

int scanAngle(int angle) {
servo.write(angle);
delay(300);
return getAverageDistance();
}

void loop() {
long distance = getAverageDistance();
Serial.println(distance);

if (distance == 0 || distance > 300) {
digitalWrite(motorLeft, LOW);
digitalWrite(motorRight, LOW);
return;
}

if (distance < 20) {
// توقّف مؤقت
digitalWrite(motorLeft, LOW);
digitalWrite(motorRight, LOW);
delay(200);

// فحص الاتجاهات
int left = scanAngle(150);
int right = scanAngle(30);
servo.write(angleCenter);
delay(100);

if (left > right) {
  // انعطاف لليسار
  digitalWrite(motorLeft, HIGH);
  digitalWrite(motorRight, LOW);
} else {
  // انعطاف لليمين
  digitalWrite(motorLeft, LOW);
  digitalWrite(motorRight, HIGH);
}

delay(500);  // وقت الانعطاف

} else {
// حركة أمامية
digitalWrite(motorLeft, HIGH);
digitalWrite(motorRight, HIGH);
}

delay(50); // تخفيف الضغط على الحلقة
}
تنزيل

@Eb171767 Eb171767 deleted the patch-1 branch July 23, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant