mirror of
https://github.com/acabon29/ia_hackathon.git
synced 2026-09-22 19:36:53 +02:00
add project
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// const int bouton = 2; // the button is connected to pin 2 of the Adruino board
|
||||
const int relais_moteur = 2; // the relay is connected to pin 3 of the Adruino board
|
||||
int etatBouton;
|
||||
unsigned long currentMillis = 0;
|
||||
const long interval = 500;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
// pinMode(bouton, INPUT);
|
||||
pinMode(relais_moteur, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// Check if data is received
|
||||
if (Serial.available() > 0)
|
||||
{
|
||||
char command = Serial.read(); // Read the received command
|
||||
|
||||
if (command == 'R') {
|
||||
digitalWrite(relais_moteur, HIGH);
|
||||
// currentMillis = millis();
|
||||
delay(500);
|
||||
digitalWrite(relais_moteur, LOW);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// other method (does not work) :
|
||||
// if (command == 'R') {
|
||||
// digitalWrite(relais_moteur, HIGH);
|
||||
// currentMillis = millis();
|
||||
// }
|
||||
// if (currentMillis != 0 && millis() - currentMillis > interval)
|
||||
// {
|
||||
// digitalWrite(relais_moteur, LOW);
|
||||
// currentMillis = 0;
|
||||
// }
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
const int trigPin = 11; // Trigger
|
||||
const int echoPin = 12; // Echo
|
||||
long duree; // durée de l'echo
|
||||
int distance; // distance
|
||||
|
||||
void setup() {
|
||||
pinMode(trigPin, OUTPUT); // Configuration du port du Trigger comme une SORTIE
|
||||
pinMode(echoPin, INPUT); // Configuration du port de l'Echo comme une ENTREE
|
||||
Serial.begin(9600); // Démarrage de la communication série
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Émission d'un signal de durée 10 microsecondes
|
||||
digitalWrite(trigPin, LOW);
|
||||
delayMicroseconds(5);
|
||||
digitalWrite(trigPin, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(trigPin, LOW);
|
||||
|
||||
// Écoute de l'écho
|
||||
duree = pulseIn(echoPin, HIGH);
|
||||
|
||||
// Calcul de la distance
|
||||
distance = duree*0.034/2;
|
||||
|
||||
// Affichage de la distance dans le Moniteur Série
|
||||
Serial.print("Distance : ");
|
||||
Serial.print(distance);
|
||||
Serial.println("cm");
|
||||
}
|
||||
Reference in New Issue
Block a user