that_one_nigga_you_k

interruption that works

Apr 1st, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. int A, B, i=0;
  2.  
  3. void setup() {
  4. // put your setup code here, to run once:
  5. pinMode(4, INPUT);
  6. pinMode(3, INPUT);
  7. Serial.begin(38400);
  8. attachInterrupt(digitalPinToInterrupt(2), fn, CHANGE);
  9. attachInterrupt(digitalPinToInterrupt(3), fn, CHANGE);
  10. }
  11.  
  12. void loop() {
  13. // put your main code here, to run repeatedly:
  14.  
  15.  
  16. }
  17.  
  18. void fn(){
  19. int ia = i;
  20.  
  21.  
  22. if(A==B){
  23. if(A!=digitalRead(4)){
  24. i++;
  25. A = digitalRead(4);
  26. }
  27. if(B!=digitalRead(3)){
  28. i--;
  29. B = digitalRead(3);
  30. }
  31. }
  32.  
  33. else{
  34. if(A!=digitalRead(4)){
  35. i--;
  36. A = digitalRead(4);
  37. }
  38. if(B!=digitalRead(3)){
  39. i++;
  40. B = digitalRead(3);
  41. }
  42. }
  43.  
  44. if(i != ia){
  45. Serial.print("\n\n\n\n\n\n\n\n pulsos:");
  46. Serial.println(i);
  47. }
  48. }
Add Comment
Please, Sign In to add comment