Advertisement
mich29800

duree BP

Dec 27th, 2020 (edited)
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define pin_gauche 4    // BP gauche en 4
  2. #define pin_droit 2 // BP droit en 2
  3. byte bpg=7;           // etat BP gauche
  4. byte bpd=7;           // etat BP droit
  5. unsigned long duree_bpg=0;  // durée appui sur BP gauche
  6. unsigned long duree_bpd=0;  // durée appui sur BP droit
  7. unsigned long temps;  // variable pour calcul base de temps
  8. int duree_appui=2000; //durée appui sur Bp en ms
  9.  
  10. void setup() {
  11. pinMode(pin_gauche,INPUT_PULLUP);
  12. pinMode(pin_droit,INPUT_PULLUP);
  13. }
  14. void acqui_bp()
  15. {
  16. bpg=(bpg<<1|digitalRead(pin_gauche))&7;
  17. bpd=(bpd<<1|digitalRead(pin_droit))&7;
  18. if (bpg==6){duree_bpg=millis();}
  19. if (bpg==1){if ((millis()-duree_bpg)>duree_appui){bpg=5;}}
  20. if (bpd==6){duree_bpd=millis();}
  21. if (bpd==1){if ((millis()-duree_bpd)>duree_appui){bpd=5;}}
  22. }
  23. void loop() {
  24. if (millis()-temps >=10)      //base de temps 10ms
  25. {acqui_bp();temps=millis();}  // pour acquisition etat des Bp
  26. if (bpg==1)
  27. { //action appui court bpg;
  28.   bpg=7;
  29. }
  30. if (bpg==5)
  31. { //action appui long bpg;
  32.   bpg=7;
  33. }
  34. if (bpd==1)
  35. { //action appui court bpd;
  36.   bpd=7;
  37. }
  38. if (bpd==5)
  39. { //action appui long bpd;
  40.   bpd=7;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement