Skip to content

Xodage 2d2 #11983

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
Momoo2100 opened this issue Sep 19, 2024 · 0 comments
Closed

Xodage 2d2 #11983

Momoo2100 opened this issue Sep 19, 2024 · 0 comments
Assignees
Labels
Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug

Comments

@Momoo2100
Copy link

int echoPin = 7;
int triggerPin = 8;

int distance = 0;
long readUltrasonicDistance(int triggerPin, int echoPin);

void setup() {
Serial.begin(9600);
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);

pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}

void loop() {
distance = 0.01723 * readUltrasonicDistance(triggerPin, echoPin);
Serial.println(distance);

if (distance >= 200) {
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
} else {
if (distance < 200 && distance >= 80) {
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
} else {
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
}
}

delay(10); // Retarde un peu pour améliorer la simulation
}

// Définition de la fonction readUltrasonicDistance
long readUltrasonicDistance(int triggerPin, int echoPin) {
// Envoie une impulsion de 10 microsecondes pour déclencher le capteur à ultrasons
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);

// Lis la durée de l'impulsion renvoyée par le capteur
long duration = pulseIn(echoPin, HIGH);

// Calcule la distance en cm
long distance = duration * 0.034 / 2;

return distance;
}

@per1234 per1234 self-assigned this Sep 19, 2024
@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
@per1234 per1234 added the Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug label Sep 19, 2024
@per1234 per1234 mentioned this issue Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Invalid Off topic for this repository, or a bug report determined to not actually represent a bug
Projects
None yet
Development

No branches or pull requests

2 participants