v12345vtm

3keer kloppen = bellen

Mar 24th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. int pin = A0;
  2. int x = 0;
  3. int klop = 1;
  4. unsigned long duration;
  5. unsigned long previousMillis ;
  6. unsigned long currentMillis ;
  7. unsigned long kloptijd1 ;
  8. //unsigned long kloptijd3 ;
  9. void setup()
  10. {
  11. Serial.begin(115200);
  12. pinMode(pin, INPUT);
  13. pinMode(11, OUTPUT); //buzzer
  14. pinMode(2, OUTPUT);
  15. pinMode(3, OUTPUT);
  16. pinMode(4, OUTPUT);
  17.  
  18. kloptijd1 = millis();
  19. }
  20. void loop()
  21. {
  22. duration = pulseIn(pin, HIGH);
  23.  
  24. if (((unsigned long)(millis() - kloptijd1) >= 1000) )
  25. {
  26. unsigned long verschil = millis() - kloptijd1;
  27. digitalWrite(2, LOW);
  28. digitalWrite(3, LOW);
  29. digitalWrite(4, LOW);
  30. Serial.println("timeout " + String(verschil));
  31. klop = 1; //reset teller
  32. Serial.println (kloptijd1);
  33. }
  34.  
  35.  
  36.  
  37.  
  38. if (duration > 0)
  39. {
  40. currentMillis = millis();
  41. }
  42. // Serial.println (x++);
  43. // How much time has passed, accounting for rollover with subtraction!
  44. if ((unsigned long)(currentMillis - previousMillis) >= 300) {
  45. // antidender , we komen hier niet rap direkt terug
  46. digitalWrite(2, HIGH);
  47. Serial.print (" klop : ");
  48. Serial.println (klop++);
  49. //laatste geziene klop , om :
  50. kloptijd1 = millis();
  51. Serial.print ("laatste klop om : ");
  52. Serial.println (kloptijd1);
  53.  
  54.  
  55. if (klop == 2) {
  56. digitalWrite(2, HIGH);
  57. // digitalWrite(3, HIGH);
  58. // digitalWrite(4, HIGH);
  59. // Serial.print (" DING DONG : ");
  60. // klop = 1; //reset teller
  61. }
  62.  
  63.  
  64. if (klop == 3) {
  65. digitalWrite(2, HIGH);
  66. digitalWrite(3, HIGH);
  67. // digitalWrite(4, HIGH);
  68. // Serial.print (" DING DONG : ");
  69. // klop = 1; //reset teller
  70. }
  71.  
  72.  
  73.  
  74.  
  75. if (klop == 4) {
  76. digitalWrite(2, HIGH);
  77. digitalWrite(3, HIGH);
  78. digitalWrite(4, HIGH);
  79. Serial.println (" DING DONG : ");
  80. klop = 1; //reset teller
  81.  
  82.  
  83.  
  84. for (int x = 1; x <= 3; x++)
  85. {
  86. analogWrite(11, 255);
  87. delay(600);
  88.  
  89. analogWrite(11, 0);
  90. delay(50);
  91. }
  92.  
  93.  
  94.  
  95.  
  96. }
  97.  
  98.  
  99.  
  100.  
  101. // Use the snapshot to set track time until next event
  102. previousMillis = currentMillis;
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment