-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobercik5.py
73 lines (55 loc) · 1.35 KB
/
robercik5.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
59
60
61
62
63
64
65
66
67
68
69
70
71
#first comment in this code:)
import RPi.GPIO as GPIO
import tkinter as tk
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(36, GPIO.OUT)
rightRear = GPIO.PWM(36, 100)
GPIO.setup(38, GPIO.OUT)
leftRear = GPIO.PWM(38, 100)
GPIO.setup(35, GPIO.OUT)
rightFront = GPIO.PWM(35, 100)
GPIO.setup(37, GPIO.OUT)
leftFront = GPIO.PWM(37, 100)
def stop():
rightFront.ChangeDutyCycle(0)
leftFront.ChangeDutyCycle(0)
rightRear.ChangeDutyCycle(0)
leftRear.ChangeDutyCycle(0)
def fwd():
stop()
rightFront.ChangeDutyCycle(100)
leftFront.ChangeDutyCycle(100)
def bwd():
stop()
rightRear.ChangeDutyCycle(100)
leftRear.ChangeDutyCycle(100)
def left():
stop()
leftFront.ChangeDutyCycle(100)
rightRear.ChangeDutyCycle(100)
def right():
stop()
rightFront.ChangeDutyCycle(100)
leftRear.ChangeDutyCycle(100)
rightFront.start(0)
leftFront.start(0)
rightRear.start(0)
leftRear.start(0)
print(3)
def key_input(event):
key_press = event.keysym.lower()
print(key_press)
if key_press == 'up':
fwd()
elif key_press == 'down':
bwd()
elif key_press == 'left':
left()
elif key_press == 'right':
right()
elif key_press == 'space':
stop()
command = tk.Tk()
command.bind_all('<Key>', key_input)
command.mainloop()