From e363a0d6ab03c6f5faf1f5bb73e9f3a419599af4 Mon Sep 17 00:00:00 2001 From: Alan Wang <44191076+alankrantas@users.noreply.github.com> Date: Wed, 12 Jan 2022 12:56:04 +0800 Subject: [PATCH] Update rc_car.py --- rc_car/rc_car.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rc_car/rc_car.py b/rc_car/rc_car.py index 49cda96..b8e1200 100644 --- a/rc_car/rc_car.py +++ b/rc_car/rc_car.py @@ -1,6 +1,7 @@ # For the micro:bit RC car RADIO_CHANNEL = 42 # radio channel: 0~255 +SPEED = 1023 # wheel speed: 0~1023 from microbit import display, Image, sleep, pin1, pin2, pin8, pin12 import radio @@ -27,28 +28,28 @@ while True: if direction == 'forward': display.show(Image.ARROW_N) - motor_right_A.write_digital(1) + motor_right_A.write_analog(SPEED) motor_right_B.write_digital(0) - motor_left_A.write_digital(1) + motor_left_A.write_analog(SPEED) motor_left_B.write_digital(0) elif direction == 'backward': display.show(Image.ARROW_S) motor_right_A.write_digital(0) - motor_right_B.write_digital(1) + motor_right_B.write_analog(SPEED) motor_left_A.write_digital(0) - motor_left_B.write_digital(1) + motor_left_B.write_analog(SPEED) elif direction == 'left': display.show(Image.ARROW_W) motor_right_A.write_digital(0) - motor_right_B.write_digital(1) - motor_left_A.write_digital(1) + motor_right_B.write_analog(SPEED) + motor_left_A.write_analog(SPEED) motor_left_B.write_digital(0) elif direction == 'right': display.show(Image.ARROW_E) - motor_right_A.write_digital(1) + motor_right_A.write_analog(SPEED) motor_right_B.write_digital(0) motor_left_A.write_digital(0) - motor_left_B.write_digital(1) + motor_left_B.write_analog(SPEED) else: display.show(Image.SQUARE) motor_right_A.write_digital(0)