Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1.  
  2. //---Variables---
  3. int BoutonMoins = 2;
  4. int BoutonPlus = 3;
  5. int Pin[5] = {6,7,8,9,10};
  6. int NbrActuel = 0;
  7. int NbrAffiche = 0;
  8.  
  9. void Affichage(int nombre);
  10.  
  11. //---Initialisation---
  12.  
  13. void setup()
  14. {
  15. pinMode(11,OUTPUT);
  16. pinMode(12,OUTPUT);
  17. Serial.begin(9600);
  18. pinMode(BoutonMoins,INPUT_PULLUP);
  19. pinMode(BoutonPlus,INPUT_PULLUP);
  20. for (int i=0;i<=4;i++)
  21. {
  22. pinMode(Pin[i],OUTPUT);
  23. }
  24. Serial.println("---Initialisation Terminer---");
  25. Serial.println("Appuyer sur un des deux bouton !");
  26. }
  27.  
  28. // ---Debut Programme Principale---
  29.  
  30. void loop()
  31. {
  32. boolean EtatBoutonMoins = digitalRead(BoutonMoins);
  33. boolean EtatBoutonPlus = digitalRead(BoutonPlus);
  34.  
  35. if (!EtatBoutonMoins == HIGH)
  36. {
  37. if (NbrActuel > 0)
  38. {
  39. Serial.println("---Bouton - Activer!---");
  40. NbrActuel = NbrActuel - 1;
  41. digitalWrite(12,HIGH);
  42. Affichage(NbrActuel);
  43. delay(1800);
  44. digitalWrite(12,LOW);
  45. }
  46. }
  47. if (!EtatBoutonPlus == HIGH)
  48. {
  49. if (NbrActuel < 5)
  50. {
  51. Serial.println("---Bouton + Activer!---");
  52. NbrActuel = NbrActuel + 1;
  53. digitalWrite(11,HIGH);
  54. Affichage(NbrActuel);
  55. delay(800);
  56. digitalWrite(11,LOW);
  57. }
  58. }
  59. if (!EtatBoutonPlus && !EtatBoutonMoins == HIGH)
  60. {
  61. Serial.println("---Remise a zero---");
  62. Affichage(0);
  63. }
  64. delay (100);
  65. }
  66. //---Debut Fonctions---
  67.  
  68. void Affichage(int nombre)
  69. {
  70. if (nombre > NbrAffiche )
  71. {
  72. for (int j=0;j<nombre;j++)
  73. {
  74. digitalWrite(Pin[j],HIGH);
  75. }
  76. NbrAffiche = NbrActuel;
  77. Serial.print("Nombre actuellement afficher :");
  78. Serial.println(NbrAffiche);
  79. }
  80.  
  81. if (nombre < NbrAffiche)
  82. {
  83. for (int h=5;h>=nombre;h--)
  84. {
  85. digitalWrite(Pin[h],LOW);
  86. }
  87. NbrAffiche = NbrActuel;
  88. Serial.print("Nombre actuellement afficher :");
  89. Serial.println(NbrAffiche);
  90. }
  91. delay(100);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement