-
Notifications
You must be signed in to change notification settings - Fork 1
/
control.py
59 lines (50 loc) · 1.14 KB
/
control.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
52
53
54
55
56
57
58
try:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
except:
class GPIO(object):
"""Fake class to test it on PC."""
OUT = IN = 0
@staticmethod
def setup(*args):
pass
@staticmethod
def output(*args):
pass
@staticmethod
def start(*args):
pass
@staticmethod
def stop(*args):
pass
@staticmethod
def PWM(*args):
return GPIO
import os
# Hardware config
PIN_SPEED_CTRL = 11
PIN_GO_FORWARD_BTN = 13
PWM = None
FORWARD_SLOW = 66
BACKWARD_SLOW = 25
FORWARD_FAST = 100
BACKWARD_FAST = 0
def go(dutycycle):
global PWM
if PWM:
PWM.stop()
PWM = None
GPIO.setup(PIN_SPEED_CTRL, GPIO.OUT)
PWM = GPIO.PWM(PIN_SPEED_CTRL, 30)
PWM.start(dutycycle)
def stop():
global PWM
GPIO.setup(PIN_SPEED_CTRL, GPIO.IN)
if PWM:
PWM.stop()
PWM = None
def choo():
os.system("play sounds/choo.mp3 &") # needs sox installed.
def is_pushed():
GPIO.setup(PIN_GO_FORWARD_BTN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
return GPIO.input(PIN_GO_FORWARD_BTN)