-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths1.py
71 lines (66 loc) · 1.38 KB
/
s1.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
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 14 20:18:04 2020
@author: ohtak
"""
gpio_pin = 17
gpio_pin2 = 27
#1= left
#2= right
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpio_pin , GPIO.OUT)
GPIO.setup(gpio_pin2 , GPIO.OUT)
#27 = right
def Right(none):
GPIO.output(gpio_pin, 0)
GPIO.output(gpio_pin2, 1)
time.sleep(0.60)
Off("a")
return 0
def Left(none):
GPIO.output(gpio_pin, 1)
GPIO.output(gpio_pin2, 0)
time.sleep(0.60)
Off("a")
return 0
def Straight(none):
for i in range(2):
Right(0)
time.sleep(0.1)
Off("r")
Left(0)
time.sleep(0.17)
Off("l")
return 0
def Off(which):
if which == "r":
GPIO.output(gpio_pin2 , 0)
elif which == "l":
GPIO.output(gpio_pin , 0)
elif which == "a":
GPIO.output(gpio_pin , 0)
GPIO.output(gpio_pin2 , 0)
return 0
while True:
try:
answer = ""
answer = raw_input("Chose, s or r or l or ss or e.")
if answer == "s":
Straight(0)
elif answer == "r":
Right(0)
elif answer == "l":
Left(0)
elif answer == "ss":
Off("a")
elif answer == "e":
break
else:
print("What?")
except KeyboardInterrupt:
print("safe end.")
break
GPIO.cleanup()
print("All end.")