Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int photocellPin = 0;
- int photocellReading;
- int PinBouton = 12; // Identifiant pin utilisée avec le BP
- int compteur_etat = 0; //compteur état de fonctionnement
- unsigned long temps = 0; //pour tempos
- void setup(void) {
- Serial.begin(9600);
- pinMode(7,OUTPUT); // Moteur n°1
- pinMode(8,OUTPUT); // Moteur n°2
- pinMode(12,INPUT_PULLUP); // Bouton poussoir du levier "sans résistance"
- }
- void loop(void) {
- {
- photocellReading = analogRead(photocellPin);
- Serial.print("Luminosité = ");
- Serial.print(photocellReading);
- delay(10); // Lecture perpétuelle de la photorésistance sur l'écran toute les 10 ms
- }
- boolean etatBouton = digitalRead(PinBouton);
- if (etatBouton==0) // Si bouton appuyé : on lance tous les programes à la suite
- {
- switch (compteur_etat)
- {
- case 0:
- {
- digitalWrite(7,HIGH);
- digitalWrite(8,HIGH); // Moteur n°1 et 2 amorcent l'étiquette
- compteur_etat=1;
- temps=millis();
- break;
- }
- case 1:
- {
- if ((photocellReading < 800)&&((millis()-temps)>=1000))
- {
- Serial.println(" - GO !!! ");
- compteur_etat=2;
- }
- break;
- }
- case 2:
- {
- if (photocellReading >= 800)
- {
- Serial.println(" - STOP ! ");
- digitalWrite(7,LOW); // Moteur n°1 stoppe
- compteur_etat=3;
- temps=millis();
- }
- break;
- }
- case 3:
- {
- if ((millis()-temps)>=2000) // Moteur n°2 tourne 2000 ms avant de se stopper
- {
- digitalWrite(8,LOW);
- compteur_etat=0;
- }
- break;
- }
- }
- }
- if (etatBouton==1) // Si bouton éteint, tout doit s'arreter (sécurité)
- {
- digitalWrite(7,LOW);
- digitalWrite(8,LOW);
- compteur_etat=0; // à conserver si on repart du début de cycle au réappui sur le BP...
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement