-
Notifications
You must be signed in to change notification settings - Fork 0
/
sviat_move.py
96 lines (82 loc) · 2.29 KB
/
sviat_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3
# File name : findline.py
# Description : line tracking
# Website : www.adeept.com
# E-mail : [email protected]
# Author : William
# Date : 2019/02/23
import RPi.GPIO as GPIO
import time
import move
import LED
from rpi_ws281x import *
'''
status = 1 #Motor rotation
forward = 1 #Motor forward
backward = 0 #Motor backward
left_spd = num_import_int('E_M1:') #Speed of the car
right_spd = num_import_int('E_M2:') #Speed of the car
left = num_import_int('E_T1:') #Motor Left
right = num_import_int('E_T2:') #Motor Right
'''
line_pin_right = 19
line_pin_middle = 16
line_pin_left = 20
'''
left_R = 15
left_G = 16
left_B = 18
right_R = 19
right_G = 21
right_B = 22
on = GPIO.LOW
off = GPIO.HIGH
spd_ad_1 = 1
spd_ad_2 = 1
'''
def my_move(timer, speed, direction, left_right):
while timer>0:
move.move(speed, direction, left_right, 1)
timer = timer - 1
time.sleep(0.2)
def setup():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(line_pin_right,GPIO.IN)
GPIO.setup(line_pin_middle,GPIO.IN)
GPIO.setup(line_pin_left,GPIO.IN)
#motor.setup()
def run():
status_right = GPIO.input(line_pin_right)
status_middle = GPIO.input(line_pin_middle)
status_left = GPIO.input(line_pin_left)
print('R%d M%d L%d\r'%(status_right,status_middle,status_left))
if status_middle == 1:
move.move(70, 'forward', 'no', 1)
elif status_left == 1:
move.move(70, 'no', 'right', 1)
elif status_right == 1:
move.move(70, 'no', 'left', 1)
else:
move.move(70, 'backward', 'no', 1)
time.sleep(0.2)
if __name__ == '__main__':
led = LED.LED()
led.colorWipe(Color(0,0,0))
# try:
# led.colorWipe(Color(0,0,0))
# led.colorWipe(Color(0, 204, 0))
# led.colorWipe(Color(255,255,255))
# except:
# led.colorWipe(Color(0,0,0))
try:
# setup()
move.setup()
my_move(timer=10, speed=70, direction='forward', left_right='no')
my_move(8, 70, 'forward', 'no')
my_move(8, 70, 'forward', 'no')
my_move(8, 70, 'forward', 'no')
except KeyboardInterrupt:
print("Ctrl + C happened")
move.destroy()
move.destroy()