Skip to content

Caaca #11984

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 20, 2024 · 1 comment
Closed

Caaca #11984

Momoo2100 opened this issue Sep 20, 2024 · 1 comment
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 20, 2024
@per1234
Copy link
Collaborator

per1234 commented Sep 20, 2024

@Momoo2100 I don't know what you are attempting to accomplish by sharing your sketch, but this is not an appropriate place for it. This is the second time (#11983).


If you are wanting to get assistance with your project, you can ask for assistance on Arduino Forum:

https://forum.arduino.cc/

but you will need to make the effort to clearly communicating what you need assistance with instead of just dumping your code as you did here.

If you only want to publish your code, do that in your own GitHub repository, not ours!

@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 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 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