Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #-*- coding: UTF-8 -*-
  3. import time
  4. import datetime
  5. import threading
  6. import RPi.GPIO as io
  7.  
  8.  
  9. io.setmode(io.BCM)
  10.  
  11. magnetic_pin = 23
  12.  
  13. def calcDistance():
  14. global counter
  15. distance = counter*perimeter
  16. MPH = float(2.23694)
  17. realDistance = distance * 20
  18. realMPH = MPH * realDistance
  19. print(realMPH)
  20. time.sleep(0.05)
  21. counter = 0
  22. global didRun
  23. print("running")
  24. didRun = 0
  25.  
  26. io.setup(magnetic_pin, io.IN, pull_up_down=io.PUD_UP) # activate input with PullUp
  27. counter = 0 # variable to count rounds
  28. register = 0 # variable to control the sensor status
  29. radius = float(0.3048) # radius of the wheel in meters
  30. pi = float(3.1416)
  31. perimeter = float(2*pi*radius)
  32. didRun = 0
  33.  
  34. while True:
  35. if io.input(magnetic_pin):
  36. if register==0:
  37. counter += 1
  38. register = 1
  39. else:
  40. if register==1:
  41. register = 0
  42.  
  43.  
  44. if didRun==0:
  45. print("RAN")
  46. calcDistance()
  47. didRun=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement