forked from SCKIMOSU/rascar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor_sck.py
52 lines (36 loc) · 958 Bytes
/
motor_sck.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
import RPi.GPIO as GPIO # import GPIO librery
import time
GPIO.setmode(GPIO.BOARD)
Motor1A = 12 #모터 1은 각각 12, 11, 35번 핀에 연결되어있다.
Motor1B = 11
Motor1E = 35
Motor2A = 15
Motor2B = 13
Motor2E = 37
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
GPIO.setup(Motor2A,GPIO.OUT)
GPIO.setup(Motor2B,GPIO.OUT)
GPIO.setup(Motor2E,GPIO.OUT)
#initial motor forward setting
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor2A,GPIO.LOW)
GPIO.output(Motor2B,GPIO.HIGH)
GPIO.output(Motor2E,GPIO.HIGH)
pwm=GPIO.PWM(Motor1E,100)
pwm2=GPIO.PWM(Motor2E,100)
# starting it with 40% dutycycle
cnt=0;
try:
while True:
pwm.start(40)
pwm2.start(40)
except KeyboardInterrupt:
GPIO.output(Motor1E,GPIO.LOW)
GPIO.output(Motor2E,GPIO.LOW)
pwm.ChangeDutyCycle(0)
pwm2.ChangeDutyCycle(0)
GPIO.cleanup()