Skip to content

Commit 5da71d9

Browse files
committed
add motor
1 parent 18d19ae commit 5da71d9

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

11.app/motor.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from machine import Pin, PWM
2+
3+
import time
4+
5+
class Motor:
6+
7+
speed_1, speed_2 = 400, 400
8+
9+
left_1, left_2, right_1, right_2 = Pin(15, Pin.OUT), Pin(12, Pin.OUT), Pin(14, Pin.OUT), Pin(25, Pin.OUT) # 4 6 7 8
10+
left_pwm, right_pwm = PWM(Pin(13), freq=256), PWM(Pin(26), freq=256) # 5 9
11+
12+
def start(self):
13+
Motor.left_pwm.duty(Motor.speed_1)
14+
Motor.right_pwm.duty(Motor.speed_2)
15+
16+
def stop(self):
17+
Motor.left_1.value(0)
18+
Motor.left_2.value(0)
19+
Motor.right_1.value(0)
20+
Motor.right_2.value(0)
21+
22+
def next(self):
23+
Motor.left_1.value(0)
24+
Motor.left_2.value(1)
25+
Motor.right_1.value(0)
26+
Motor.right_2.value(1)
27+
28+
def back(self):
29+
Motor.left_1.value(1)
30+
Motor.left_2.value(0)
31+
Motor.right_1.value(1)
32+
Motor.right_2.value(0)
33+
34+
def left(self):
35+
Motor.left_1.value(0)
36+
Motor.left_2.value(1)
37+
Motor.right_1.value(1)
38+
Motor.right_2.value(0)
39+
40+
def right(self):
41+
Motor.left_1.value(1)
42+
Motor.left_2.value(0)
43+
Motor.right_1.value(0)
44+
Motor.right_2.value(1)
45+
46+
tmp = Motor()
47+
tmp.start()
48+
tmp.next()
49+
time.sleep(2)
50+
tmp.left()
51+
time.sleep(2)
52+
tmp.right()
53+
time.sleep(2)
54+
tmp.back()

0 commit comments

Comments
 (0)