forked from Google-Developer-Student-Club-MBU/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.py
More file actions
33 lines (24 loc) · 702 Bytes
/
robot.py
File metadata and controls
33 lines (24 loc) · 702 Bytes
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
import time
import board
import pwmio
# Create a PWM object for the robot's left motor
left_motor = pwmio.PWMOut(board.D18, frequency=50)
# Create a PWM object for the robot's right motor
right_motor = pwmio.PWMOut(board.D13, frequency=50)
# Set the speed of the robot's left motor
left_motor.duty_cycle = 1000
# Set the speed of the robot's right motor
right_motor.duty_cycle = 1000
# Move the robot forward
left_motor.duty_cycle = 2000
right_motor.duty_cycle = 2000
# Wait for 2 seconds
time.sleep(2)
# Move the robot backward
left_motor.duty_cycle = 1000
right_motor.duty_cycle = 1000
# Wait for 2 seconds
time.sleep(2)
# Stop the robot
left_motor.duty_cycle = 0
right_motor.duty_cycle = 0