-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.py
51 lines (43 loc) · 1.34 KB
/
move.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
41
42
43
44
45
46
47
48
49
50
51
import os
import time
class PWM:
PIN_LEFT_FORWARD = 22
PIN_RIGHT_FORWARD = 24
PIN_LEFT_BACKWARD = 23
PIN_RIGHT_BACKWARD = 25
def __init__(self):
self.pins = [PWM.PIN_LEFT_FORWARD, PWM.PIN_LEFT_BACKWARD, PWM.PIN_RIGHT_FORWARD, PWM.PIN_RIGHT_BACKWARD]
self.values = [0, 0, 0, 0]
self.koef = [1, 1, 1, 1]
def update( self ):
str = '; '.join((("%d=%.2f" % (self.pins[index], self.values[index] * self.koef[index] / 100)) for index, item in enumerate(self.values)))
cmd = 'echo "'+str+'" > /dev/pi-blaster'
print(cmd)
os.system(cmd)
def set(self, pin, value):
try:
index = self.pins.index(pin)
except:
pass
self.values[index] = value
led = PWM()
led.set(PWM.PIN_LEFT_FORWARD, 0)
led.set(PWM.PIN_RIGHT_FORWARD, 0)
led.set(PWM.PIN_LEFT_BACKWARD, 0)
led.set(PWM.PIN_RIGHT_BACKWARD, 0)
led.update()
#while True:
# led.set(PWM.PIN_LEFT_FORWARD, 0)
# led.set(PWM.PIN_RIGHT_FORWARD, 0)
# led.set(PWM.PIN_LEFT_BACKWARD, 100)
# led.set(PWM.PIN_RIGHT_BACKWARD, 100)
# led.update()
# time.sleep(1)
# led.set(PWM.PIN_LEFT_FORWARD, 100)
# led.set(PWM.PIN_RIGHT_FORWARD, 100)
# led.set(PWM.PIN_LEFT_BACKWARD, 0)
# led.set(PWM.PIN_RIGHT_BACKWARD, 0)
# led.update()
# time.sleep(1)
#led = PWM(24)
#led.set(100)