Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. int N=32;
  2. int i;
  3. int codi[32];
  4. unsigned long tempsinicial;
  5.  
  6. void setup () {
  7. Serial.begin(9600);
  8. attachInterrupt(0, detecta_tecla, RISING);
  9. }
  10.  
  11. void loop() {
  12. }
  13.  
  14. void detecta_tecla() {
  15. detachInterrupt(0);
  16. i=0;
  17. tempsinicial=micros();
  18. attachInterrupt(0, detecta_pols, RISING);
  19. }
  20.  
  21.  
  22. void detecta_pols() {
  23. detachInterrupt(0);
  24. /*if (i==0){
  25. tempsinicial = micros();
  26. ++i;
  27. attachInterrupt(0, detecta_pols, RISING);
  28. }*/
  29. //else{
  30. unsigned long temps = micros();
  31. if (temps-tempsinicial < 1600){
  32. codi[i] = 0;
  33. }
  34. else {
  35. codi[i] = 1;
  36. }
  37. tempsinicial = temps;
  38. ++i;
  39. if (i==N){
  40. delay(1000);
  41. int j;
  42. for (j=0; j<N; ++j){
  43. Serial.print(codi[j]);
  44. }
  45. Serial.println("");
  46. attachInterrupt(0, detecta_tecla, RISING);
  47. }
  48. else{
  49. attachInterrupt(0, detecta_pols, RISING);
  50. }
  51. //}
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement