-
Notifications
You must be signed in to change notification settings - Fork 0
/
testloop.py.save
65 lines (53 loc) · 1.75 KB
/
testloop.py.save
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
import RPi.GPIO as gpio
# INITIAL SETUP
enable_pin = 10 # Marked MOSI on the paddle board
left_forward = 5
left_reverse = 6
right_forward = 20
right_reverse = 16
def gpio_init():
gpio.cleanup() # clear all settings
gpio.setmode(gpio.BCM) # use the Broadcom numbering scheme
gpio.setup(enable_pin, gpio.OUT) # the enable pin that turns on the motor
gpio.output(enable_pin, gpio.LOW) # now set it low to make sure it's not on
# # set the four wheels
gpio.setup(left_forward, gpio.OUT)
gpio.setup(left_reverse, gpio.OUT)
gpio.setup(right_forward, gpio.OUT)
gpio.setup(right_reverse, gpio.OUT)
def gpio_reset_all():
# set all GPIOs to low
gpio.output(left_forward, gpio.LOW)
gpio.output(left_reverse, gpio.LOW)
gpio.output(right_forward, gpio.LOW)
gpio.output(right_reverse, gpio.LOW)
gpio_init()
direction = " "
speed = 60
while direction:
gpio_reset_all()
pwm = gpio.PWM(enable_pin, 50) # 50 is the frequency
direction=input('Entrer une direction : ')
if direction == "u":
print("forward")
gpio.output(right_forward, gpio.HIGH)
gpio.output(left_forward, gpio.HIGH)
elif direction == "j":
print("reverse")
gpio.output(right_reverse, gpio.HIGH)
gpio.output(left_reverse, gpio.HIGH)
elif direction == "k":
print("right")
gpio.output(left_reverse, gpio.HIGH)
gpio.output(right_forward, gpio.HIGH)
elif direction == "h":
print("left")
gpio.output(right_reverse, gpio.HIGH)
gpio.output(left_forward, gpio.HIGH)
elif direction == 'i':
pwm.stop()
else:
pass
pwm.start(speed) # a "speed" of 50, sends power exactly every second cycle
gpio.cleanup()
print('fin du programme')