#include <Arduino.h>
#include <Servo.h>
#include <Ultrasonic.h>
#define capteur_sortie 3
#define trigger 12
#define echo 11
#define pinMoteur1 2
#define pinMoteur2 4
Servo moteur1, moteur2;
Ultrasonic Capteur_entree(trigger,echo);
void setup() {
// put your setup code here, to run once:
pinMode(capteur_sortie, INPUT);
moteur1.attach(pinMoteur1);
moteur2.attach(pinMoteur2);
}
void loop() {
// put your main code here, to run repeatedly:
if (Capteur_entree.read() < 20)
{
moteur1.write(90);
delay(1000);
}
else
{
moteur1.write(0);
}
if (digitalRead(capteur_sortie)) // Si le capteur de sortie, qui est le bouton poussoir, est vrai.
{
moteur2.write(90); // On positionne le servomoteur à 90°
delay(1000); // On attend 1s
}
else // Si le capteur de sortie, qui est le bouton poussoir , est faux.
{
moteur2.write(0);
}
delay(10);
}