Advertisement
mich29800

Etiqueteuse

Apr 26th, 2020
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int photocellPin = 0;
  2. int photocellReading;
  3. int PinBouton = 12; // Identifiant pin utilisée avec le BP
  4. int compteur_etat = 0; //compteur état de fonctionnement
  5. unsigned long temps = 0; //pour tempos
  6.  
  7. void setup(void) {
  8.  
  9. Serial.begin(9600);
  10. pinMode(7,OUTPUT); // Moteur n°1
  11. pinMode(8,OUTPUT); // Moteur n°2
  12. pinMode(12,INPUT_PULLUP); // Bouton poussoir du levier "sans résistance"
  13. }
  14.  
  15. void loop(void) {
  16. {
  17. photocellReading = analogRead(photocellPin);
  18. Serial.print("Luminosité = ");
  19. Serial.print(photocellReading);
  20. delay(10); // Lecture perpétuelle de la photorésistance sur l'écran toute les 10 ms
  21. }
  22.  
  23. boolean etatBouton = digitalRead(PinBouton);
  24.  
  25. if (etatBouton==0) // Si bouton appuyé : on lance tous les programes à la suite
  26. {
  27.   switch (compteur_etat)
  28.   {
  29.   case 0:
  30.   {
  31.     digitalWrite(7,HIGH);
  32.     digitalWrite(8,HIGH); // Moteur n°1 et 2 amorcent l'étiquette
  33.     compteur_etat=1;
  34.     temps=millis();
  35.     break;
  36.   }
  37.   case 1:
  38.   {
  39.     if ((photocellReading < 800)&&((millis()-temps)>=1000))
  40.       {
  41.       Serial.println(" - GO !!! ");
  42.       compteur_etat=2;
  43.       }
  44.     break;
  45.   }
  46.  
  47.   case 2:
  48.   {
  49.     if (photocellReading >= 800)
  50.       {
  51.       Serial.println(" - STOP ! ");
  52.       digitalWrite(7,LOW); // Moteur n°1 stoppe
  53.       compteur_etat=3;
  54.       temps=millis();
  55.       }
  56.     break;
  57.   }
  58.   case 3:
  59.   {
  60.     if ((millis()-temps)>=2000)   // Moteur n°2 tourne 2000 ms avant de se stopper
  61.       {
  62.       digitalWrite(8,LOW);
  63.       compteur_etat=0;
  64.       }
  65.     break;
  66.   }
  67.   }
  68. }
  69.  
  70. if (etatBouton==1) // Si bouton éteint, tout doit s'arreter (sécurité)
  71. {
  72.   digitalWrite(7,LOW);
  73.   digitalWrite(8,LOW);
  74.   compteur_etat=0;        // à conserver si on repart du début de cycle au réappui sur le BP...
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement