Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #-*- coding: UTF-8 -*-
- import time
- import datetime
- import threading
- import RPi.GPIO as io
- io.setmode(io.BCM)
- magnetic_pin = 23
- def calcDistance():
- global counter
- distance = counter*perimeter
- MPH = float(2.23694)
- realDistance = distance * 20
- realMPH = MPH * realDistance
- print(realMPH)
- time.sleep(0.05)
- counter = 0
- global didRun
- print("running")
- didRun = 0
- io.setup(magnetic_pin, io.IN, pull_up_down=io.PUD_UP) # activate input with PullUp
- counter = 0 # variable to count rounds
- register = 0 # variable to control the sensor status
- radius = float(0.3048) # radius of the wheel in meters
- pi = float(3.1416)
- perimeter = float(2*pi*radius)
- didRun = 0
- while True:
- if io.input(magnetic_pin):
- if register==0:
- counter += 1
- register = 1
- else:
- if register==1:
- register = 0
- if didRun==0:
- print("RAN")
- calcDistance()
- didRun=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement