/*
Livraison conteneur radioactif aver serrure.
Bp Rouge pour la validation des demandes.
Bp Jaune pour simuler l'effet Hall (appuyé = aimant présent)
L'effet Hall est utilisé pour déverouiller le conteneur à la fin du cycle.
Switch : senseur du couvercle ( à gauche ouvert, à droite fermé)
Servo Serrure : à droite ouverte, vers le bas fermée.
*/
#include <Servo.h>
Servo Serrure;
#include "Wire.h" //Ecran LCD.
#include "LiquidCrystal_I2C.h"
LiquidCrystal_I2C LCD(0x27,20,4); // définit le type d'ecran lcd 20 x 4.
byte smiley1[8] = //Symbole radio haut-gauche
{0b00000,
0b00000,
0b00111,
0b00011,
0b00001,
0b00000,
0b00000,
0b00000};
byte smiley2[8] = //radio haut-milieu
{0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00100};
byte smiley3[8] = //radio haut-droite
{0b00000,
0b00000,
0b11100,
0b11000,
0b10000,
0b00000,
0b00000,
0b00000};
byte smiley4[8] = //point
{0b00000,
0b01110,
0b11111,
0b11111,
0b11111,
0b11111,
0b01110,
0b00000};
byte smiley5[8] = //radio-bas gauche
{0b11111,
0b01111,
0b00111,
0b00011,
0b00001,
0b00000,
0b00000,
0b00000};
byte smiley6[8] = //radio-bas droit
{0b11111,
0b11110,
0b11100,
0b11000,
0b10000,
0b00000,
0b00000,
0b00000};
byte tete1[8] = //tête de mort.
{0b00111,
0b01111,
0b11111,
0b11101,
0b11101,
0b11111,
0b11111,
0b11111};
byte tete2[8] =
{0b11100,
0b11110,
0b11111,
0b10111,
0b10111,
0b11111,
0b11111,
0b11111};
byte tete3[8] =
{0b11111,
0b01111,
0b00111,
0b10011,
0b11000,
0b01100,
0b00110,
0b00011};
byte tete4[8] =
{0b11111,
0b11110,
0b11100,
0b11001,
0b00011,
0b00110,
0b01100,
0b11000};
byte Os1[8] =
{0b00001,
0b00011,
0b00110,
0b01100,
0b11000,
0b10000,
0b00000,
0b00000};
byte Os2[8] =
{0b10000,
0b11000,
0b01100,
0b00110,
0b00011,
0b00001,
0b00000,
0b00000};
int positionCounter=0;
int const LedR=2;
int const LedJ=3;
int const Buzzer=12;
int const Switch=5; //switch du couvercle. A droite = couvercle fermé ! A la masse = ouvert.
int const Led13=13;
int const Bp=6;
int const Hall=7;
int HallVal=1;
int Local=0; //Faire sonner plusieurs fois l'alarme "Local contaminé".
int Couvercle=0; //Pour la boucle "TWELVE"
int Confirm=1; //Pour la boucle "TWELVE". 1 car Bp en PullUp
bool Alarm=true; //L'alarme se déclenche une fois à l'ouverture du couvercle.
bool checkBp=false; //vérifier l'etat du bouton poussoir.
void setup() {
Serrure.attach(11);
Serrure.write(95); //ouverture de la serrure. Pas zéro pour éviter les à-coups.
pinMode(Led13,OUTPUT);
pinMode(LedR, OUTPUT);
pinMode(LedJ, OUTPUT);
pinMode(Switch, INPUT_PULLUP);
pinMode(Buzzer, OUTPUT);
pinMode(Bp, INPUT_PULLUP);
pinMode(Hall, INPUT_PULLUP);
digitalWrite(Led13,LOW);
LCD.init(); // initialisation de l'afficheur LCD.backlight();
LCD.backlight();
tone(Buzzer,100,1500);
LCD.clear();
LCD.setCursor(0,1);
LCD.print("FERMEZ LE COUVERCLE");
delay(5000); //permetrre de fermer le couvercle après mise sur ON.
Serrure.write(5); //fermeture de la serrure.
LedFlash();
LCD.clear();
LCD.setCursor(5,1);
LCD.print("COUVERCLE");
LCD.setCursor(5,2);
LCD.print("VERROUILLE");
delay(2000);
}
void loop() {
LCD.clear();
ZERO:
HallEffect(); //Permettre la réouverture.
LedFlash();
LCD.setCursor(2,0);
LCD.print("VEUILLEZ SUIVRE");
LCD.setCursor(2,1);
LCD.print("LES INSTRUCTIONS");
LCD.setCursor(1,2);
LCD.print("AFFICHEES A L'ECRAN");
delay(1500);
if ( digitalRead(Bp)== 0) {tone(Buzzer,100,1000); goto ONE;}
LCD.clear();
LCD.setCursor(3,1);
LCD.print("APPUYEZ SUR LE");
LCD.setCursor(4,2);
LCD.print("BOUTON ROUGE");
delay(1500);
LCD.clear();
if ( digitalRead(Bp)== 1) {goto ZERO;}
else {tone(Buzzer,100,1000);}
ONE:
LedFlash();
Scroll();
Dispos();
LedFlash();
Scroll();
Dispos();
TWO:
LedFlash();
LCD.setCursor(0, 0);
LCD.print("LORSQUE DISPOSITIONS");
LCD.setCursor(1, 1);
LCD.print("PRISES APPUYEZ SUR");
LCD.setCursor(2, 2);
LCD.print("LE BOUTON ROUGE");
CheckBp();
if(checkBp==false) {goto TWO;}
LCD.clear();
Serrure.write(95); //déverrouillé.
tone(Buzzer,100,1000);
delay(500);
LCD.clear();
THREE:
LedFlash();
LCD.setCursor(5,0);
LCD.print("CONTENEUR");
LCD.setCursor(4,1);
LCD.print("DEVERROUILLE");
LCD.setCursor(4,2);
LCD.print("COULISSEZ LE");
LCD.setCursor(1,3);
LCD.print("COUVERCLE => => =>");
if(digitalRead(Switch)==HIGH)
{goto THREE;}
Ouvert(); //Couvercle ouvert on reste dans le void Ouvert().
}
// Sous-Programmes
void LedFlash()
{
digitalWrite(LedR, HIGH);
delay(400);
digitalWrite(LedJ, HIGH);
delay(400);
digitalWrite(LedR, LOW);
delay(400);
digitalWrite(LedJ, LOW);
delay(400);
}
void CheckBp() //Verifier le Bp rouge au début du programme.
{
if(digitalRead(Bp)==LOW)
{checkBp=true;}
}
void Scroll() //Message Scroll
{
LCD.clear();
LCD.createChar(1, smiley1); //Respecter l'ordre, create-setCursor-Print.
LCD.setCursor(2, 0); // move cursor to (x,y)
LCD.print(char(1));
LCD.createChar(2, smiley2);
LCD.setCursor(3, 0);
LCD.print(char(2));
LCD.createChar(3, smiley3);
LCD.setCursor(4, 0);
LCD.print(char(3));
LCD.createChar(4, smiley4);
LCD.setCursor(3, 1);
LCD.print(char(4));
LCD.createChar(5, smiley5);
LCD.setCursor(2, 2);
LCD.print(char(5));
LCD.createChar(6, smiley6);
LCD.setCursor(4, 2);
LCD.print(char(6));
LCD.setCursor(0,3);
LCD.print("-DANGER-");
delay(500);
for (positionCounter=0; positionCounter <11; positionCounter++)
{LCD.scrollDisplayRight(); delay(300);} //Scroll affichage.
LCD.clear();
}
void Dispos() //Message dispositions.
{
LCD.clear();
LCD.setCursor(5, 0);
LCD.print("ATTENTION");
delay(1200);
LCD.noDisplay();
delay(400);
LCD.display();
delay(1000);
LCD.setCursor(0, 1);
LCD.print("MATERIEL RADIOACTIF");
delay(1200);
LCD.setCursor(5, 2);
LCD.print("PRENEZ VOS");
delay(500);
LCD.setCursor(4, 3);
LCD.print("DISPOSITIONS");
delay(2000);
LCD.clear();
}
void Alarme() //A l'ouverture du couvercle sonnerie d'alarme une seule fois.
{
if(Alarm==true)
{tone(Buzzer,150,1000);delay(1100);tone(Buzzer,100,1500);
Alarm=false;} //ne sonne qu'une seule fois couvercle ouvert.
delay(100);
}
void Ouvert() //Après ouverture du couvercle on Loop ici.
{
tone(Buzzer,100,1000);
delay(1000);
LedFlash();
SIX:
LCD.clear();
LCD.setCursor(5, 1);
LCD.print("CONTENEUR");
LCD.setCursor(6, 2);
LCD.print("OUVERT");
delay(2500);
Alarme();
LCD.clear();
LCD.setCursor(7, 0);
LCD.print("ALERTE");
LCD.setCursor(6, 1);
LCD.print("TAUX DE");
LCD.setCursor(4, 2);
LCD.print("RADIOACTIVITE");
LCD.setCursor(6, 3);
LCD.print("-MAXIMUM-");
delay(2050);
LedFlash();
LCD.clear();
LCD.setCursor(5,0 );
LCD.print("RECUPEREZ");
LCD.setCursor(1, 1);
LCD.print("LES DEUX ELEMENTS");
LCD.setCursor(3, 2);
LCD.print("PUIS REFERMEZ");
LCD.setCursor(4, 3);
LCD.print("LE CONTENEUR !");
delay(2000);
if(digitalRead(Switch)==LOW)
{goto SIX;}
LCD.clear();
TWELVE:
LCD.setCursor(4,0 );
LCD.print("CONFIRMEZ LA");
LCD.setCursor(4,1 );
LCD.print("FERMETURE EN");
LCD.setCursor(2,2 );
LCD.print("APPUYANT SUR LE");
LCD.setCursor(4,3 );
LCD.print("BOUTON ROUGE");
delay(1000);
Couvercle=digitalRead(Switch);
Confirm=digitalRead(Bp);
delay(10);
if(Couvercle==1 && Confirm==0)
{Serrure.write(5); tone(Buzzer,250,750);delay(760);Contamine();} //verrouillé.
else {goto TWELVE;}
}
void Contamine() //Si on referme le couvercle après son ouverture on Loop ici.
{
SEVEN:
LedFlash();
LCD.clear();
delay(300);
if(Local<3)
{tone(Buzzer,200,1500); delay(1510);tone(Buzzer,300,1500);++Local;}
LCD.setCursor(7, 1);
LCD.print("LOCAL");
LCD.setCursor(5, 2);
LCD.print("CONTAMINE");
delay(1000);
LCD.noDisplay();
delay(500);
LCD.display();
delay(1300);
TeteDeMort();
if(digitalRead(Switch)==HIGH)
{goto SEVEN;}
LCD.clear();
EIGHT:
LedFlash();
tone(Buzzer,200,1500); delay(1510);tone(Buzzer,300,1500);
LCD.setCursor(4, 1);
LCD.print("REFERMEZ LE");
LCD.setCursor(5, 2);
LCD.print("CONTENEUR");
delay(1500);
if(digitalRead(Switch)==LOW)
{goto EIGHT;}
}
void TeteDeMort() //Affiche la tête de mort.
{
LCD.clear();
LCD.createChar(1, tete1); //Respecter l'ordre, create-setCursor-Print.
LCD.setCursor(8, 1); // move cursor to (x,y)
LCD.print(char(1));
LCD.createChar(2, tete2);
LCD.setCursor(9, 1);
LCD.print(char(2));
LCD.createChar(3, tete3);
LCD.setCursor(8, 2);
LCD.print(char(3));
LCD.createChar(4, tete4);
LCD.setCursor(9, 2);
LCD.print(char(4));
LCD.createChar(5, Os1);
LCD.setCursor(8, 3);
LCD.print(char(5));
LCD.createChar(6, Os2);
LCD.setCursor(9, 3);
LCD.print(char(6));
for (positionCounter=0; positionCounter <6; positionCounter++)
{LCD.scrollDisplayRight(); delay(300);}
for (positionCounter=0; positionCounter <8; positionCounter++)
{LCD.scrollDisplayLeft(); delay(300);}
HallEffect();
LCD.clear();
LCD.setCursor(3, 0);
LCD.print("FAITES APPEL A");
LCD.setCursor(2, 2);
LCD.print("'MULTI-SERVICES'");
delay(1500);
LCD.noDisplay();
delay(500);
LCD.display();
delay(1000);
LedFlash();
LCD.clear();
LCD.setCursor(5, 0);
LCD.print("ENVOYEZ UN");
LCD.setCursor(5, 1);
LCD.print("MESSAGE AU");
LCD.setCursor(3, 2);
LCD.print("06.768.512.68");
LCD.setCursor(3, 3);
LCD.print("'SUR WHATSAPP'");
delay(3500);
HallEffect();
}
void HallEffect() //L'aimant permet de déverrouiller le conteneur.
{
HallVal=digitalRead(Hall);
if(HallVal==0)
{Serrure.write(95);
delay(1000);
tone(Buzzer,300,750);
LCD.clear();
LCD.setCursor(5, 1);
LCD.print("COUVERCLE");
LCD.setCursor(4, 2);
LCD.print("DEVERROUILLE");
delay(1500);
}
}