forked from Ridhwanluthra/NLMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoders.py
40 lines (39 loc) · 887 Bytes
/
encoders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import RPi.GPIO as gpio
gpio.setmode(gpio.BCM)
leften = 18
righten = 17
dps = 30/24 #distance per spoke
gpio.setup(leften,gpio.IN)
gpio.setup(righten,gpio.IN)
counter_left = 0
counter_right = 0
c = 0
a = 0
def d_move():
while True:
global a
global c
global counter_left
global counter_right
b = a
d = c
a = gpio.input(leften)
c = gpio.input(righten)
if (a == 1 and b == 0):
counter_left += 1
#print "left counter "
#print counter_left
if (c == 1 and d == 0):
counter_right += 1
#print "right coutner "
#print counter_right
return [counter_left*dps, counter_right*dps]
def refresh():
global a
global c
global counter_left
global counter_right
counter_left = 0
counter_right = 0
c = 0
a = 0