Advertisement
GAMELASTER

Untitled

Mar 2nd, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #define IR_PIN 3
  2. #define TIME 3000
  3.  
  4. long nextUpdateTime = 0;
  5. int collisionsCount = 0;
  6. int irValue = 0;
  7.  
  8. int setup()
  9. {
  10.     Serial.begin(9600);
  11.     pinMode(IR_PIN, INPUT);
  12.     nextUpdateTime = millis() + TIME;
  13. }
  14.  
  15. int loop()
  16. {
  17.     if (nextUpdateTime >= millis())
  18.     {
  19.         Serial.print("Pocet preruseni: ");
  20.         Serial.println(collisionsCount);
  21.         collisionsCount = 0;
  22.         nextUpdateTime = millis() + TIME;
  23.     }
  24.     else
  25.     {
  26.         irValue = digitalRead(IR_PIN);
  27.         if(irValue == HIGH)
  28.         {
  29.             collisionsCount++;
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement