Ch-5 clean

This commit is contained in:
Danny Staple
2022-03-20 22:24:56 +00:00
parent 5c4ecaeb13
commit 481cac28de
8 changed files with 14 additions and 9 deletions
+3 -1
View File
@@ -1,20 +1,22 @@
import time
import robot
def straight(speed, duration):
robot.set_left(speed)
robot.set_right(speed)
time.sleep(duration)
def left(speed, duration):
robot.set_left(0)
robot.set_right(speed)
time.sleep(duration)
try:
for n in range(0, 4):
straight(0.6, 1.0)
left(0.6, 1)
finally:
robot.stop()
+2 -2
View File
@@ -8,7 +8,7 @@ motor_B2 = pwmio.PWMOut(board.GP19)
right_motor = motor_A1, motor_A2
left_motor = motor_B1, motor_B2
max_speed = 2**16-1
max_speed = 2 ** 16 - 1
def stop():
@@ -25,7 +25,7 @@ def set_speed(motor, speed):
speed = -speed
else:
direction = motor
speed = min(speed, 1) # limit to 1.0
speed = min(speed, 1) # limit to 1.0
direction[0].duty_cycle = int(max_speed * speed)
direction[1].duty_cycle = 0