Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===============================================================
- // Exploration Hardware
- // Ouvrir une porte avec un servomoteur
- // Ollivier JULLIEN
- // Juillet 2020
- //===============================================================
- //===============================================================
- // Ouverture d'une porte avec indicateurs lumineux et sonores
- // Commande par deux boutons poussoirs en appui constant
- // (ça s'ouvre ou ça se ferme que si on reste appuyé, sinon ça s'arrête)
- // Action de la porte par servo FS90
- //===============================================================
- //===============================================================
- // Matériel :
- // 2 BP (pour moi 1 DFR0029W et 1 DFR0029B)
- // 2 LEDs blanches 5 mm
- // 2 LEDs rouges 5 mm
- // 1 LED bleue 5 mm
- // 1 LED verte 5 mm
- // 6 résistances 220 ohm
- // 1 buzzer SV12-5
- // 1 mini-servomoteur FS90
- // 1 Arduino Uno
- // Câblage
- //===============================================================
- //===============================================================
- // ATTENTION :
- // La porte au repos est ouvert, donc langle Max est l'angle de la porte fermée
- // et l'angle Mini est l'angle de la porte ouverte
- // rien ne vous oblige à vous y tenir
- //===============================================================
- #include <Servo.h>
- Servo maPorte;
- const int rouge = 2;
- const int bleu = 3;
- const int blanc = 4;
- const int lampe = 5;
- const int buzzer = 6;
- const int rouge2 = 7;
- const int ok = 8;
- const int porte = 10;
- const int veille = 12;
- int rotationServo = 0;
- int evol = 1;
- long tempo;
- int tempoP = 40;
- int angleMax = 93;
- int angleMini = 3;
- bool etatRouge = true;
- bool buzzFerme = true;
- bool buzzOuvert = false;
- //===============================================================
- void setup() {
- Serial.begin(9600);
- maPorte.attach(porte);
- pinMode(bleu, INPUT);
- pinMode(blanc, INPUT);
- pinMode(rouge, OUTPUT);
- pinMode(rouge2, OUTPUT);
- pinMode(lampe, OUTPUT);
- pinMode(buzzer, OUTPUT);
- pinMode(ok, OUTPUT);
- pinMode(veille, OUTPUT);
- rotationServo = angleMax;
- digitalWrite(lampe, 0);
- }
- //===============================================================
- void loop() {
- if (digitalRead(bleu) == true) {
- actionBoutBleu ();
- } else if (digitalRead(blanc) == true) {
- actionBoutBlanc ();
- } else {
- rien ();
- }
- if ((digitalRead(bleu) == 1 && rotationServo < (angleMax - 2)) || (digitalRead(blanc) == 1 && rotationServo > (angleMini + 2))) {
- flashAlt();
- }
- if (rotationServo < (angleMini + 65)) {
- digitalWrite(lampe, true);
- } else {
- digitalWrite(lampe, false);
- }
- if (rotationServo < (angleMini + 2)) {
- allumeOK ();
- } else {
- eteintOK ();
- }
- if (rotationServo > (angleMax - 2)) {
- allumeVeilleuse();
- } else {
- eteintVeilleuse();
- }
- actionPorte ();
- }
- //===============================================================
- void flashAlt() {
- if (millis() - tempo >= 250) {
- etatRouge = !etatRouge;
- digitalWrite(rouge, etatRouge);
- digitalWrite(rouge2, !etatRouge);
- tempo = millis();
- tone (buzzer, 329, 100);
- }
- }
- void allumeVeilleuse(){
- digitalWrite(veille, true);
- if (buzzFerme == false) {
- delay(150);
- tone (buzzer, 261, 500);
- delay(600);
- tone (buzzer, 261, 700);
- buzzFerme = true;
- }
- }
- void eteintVeilleuse(){
- digitalWrite(veille, false);
- buzzFerme = false;
- }
- void allumeOK () {
- digitalWrite(ok, true);
- if (buzzOuvert == false) {
- delay(150);
- tone (buzzer, 493, 75);
- delay(150);
- tone (buzzer, 493, 75);
- buzzOuvert = true;
- }
- }
- void eteintOK () {
- digitalWrite(ok, false);
- buzzOuvert = false;
- }
- void actionPorte () {
- maPorte.write(rotationServo);
- delay(tempoP);
- }
- void actionBoutBleu () {
- if (rotationServo < angleMax) {
- rotationServo += evol;
- }
- }
- void actionBoutBlanc () {
- if (rotationServo > angleMini) {
- rotationServo -= evol;
- }
- }
- void rien () {
- digitalWrite(rouge, false);
- digitalWrite(rouge2, false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement