-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrive.py
77 lines (64 loc) · 1.25 KB
/
drive.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
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
from servo import turn
# Ustawienie pinów dla L298N
IN1 = 17
IN2 = 18
IN3 = 22
IN4 = 23
# Inicjalizacja GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)
# Funkcja do przodu
def north():
GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
GPIO.output(IN3, GPIO.HIGH)
GPIO.output(IN4, GPIO.LOW)
# Funkcja do tyłu
def south():
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.HIGH)
GPIO.output(IN3, GPIO.LOW)
GPIO.output(IN4, GPIO.HIGH)
# Funkcja do zatrzymania silników
def stop():
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
GPIO.output(IN3, GPIO.LOW)
GPIO.output(IN4, GPIO.LOW)
def drive(direction):
if direction == "north":
turn('initial')
north()
time.sleep(0.5)
stop()
if direction == "south":
turn('initial')
south()
time.sleep(0.5)
stop()
if direction == "northwest":
turn('left')
north()
time.sleep(0.5)
stop()
if direction == "northeast":
turn('right')
north()
time.sleep(0.5)
stop()
if direction == "southwest":
turn('left')
south()
time.sleep(0.5)
stop()
if direction == "southeast":
turn('right')
south()
time.sleep(0.5)
stop()