Skip to content

Instantly share code, notes, and snippets.

@RobinBoers
Last active July 21, 2021 08:56
Show Gist options
  • Save RobinBoers/d154e3096af5d8e66bbac757d892396f to your computer and use it in GitHub Desktop.
Save RobinBoers/d154e3096af5d8e66bbac757d892396f to your computer and use it in GitHub Desktop.
Script for a remote car control using :MOVE motor and another microbit for the micro:bit
# Script for the :MOVE motor
def on_received_value(name, value):
if value == 0:
moveMotorZIP.set_color(Kitronik_Move_Motor.colors(Kitronik_Move_Motor.ZipLedColors.WHITE))
Kitronik_Move_Motor.move(Kitronik_Move_Motor.DriveDirections.FORWARD, speed)
elif value == 1:
moveMotorZIP.set_color(Kitronik_Move_Motor.colors(Kitronik_Move_Motor.ZipLedColors.WHITE))
Kitronik_Move_Motor.move(Kitronik_Move_Motor.DriveDirections.REVERSE, speed)
elif value == 2:
moveMotorZIP.set_color(Kitronik_Move_Motor.colors(Kitronik_Move_Motor.ZipLedColors.WHITE))
Kitronik_Move_Motor.spin(Kitronik_Move_Motor.SpinDirections.LEFT, turnSpeed)
elif value == 3:
moveMotorZIP.set_color(Kitronik_Move_Motor.colors(Kitronik_Move_Motor.ZipLedColors.WHITE))
Kitronik_Move_Motor.spin(Kitronik_Move_Motor.SpinDirections.RIGHT, turnSpeed)
else:
moveMotorZIP.set_color(Kitronik_Move_Motor.colors(Kitronik_Move_Motor.ZipLedColors.RED))
Kitronik_Move_Motor.stop()
radio.on_received_value(on_received_value)
moveMotorZIP: Kitronik_Move_Motor.MoveMotorZIP = None
turnSpeed = 0
speed = 0
speed = 100
turnSpeed = 40
radio.set_group(3)
moveMotorZIP = Kitronik_Move_Motor.create_move_motor_zipled(4)
Kitronik_Move_Motor.set_ultrasonic_units(Kitronik_Move_Motor.Units.CENTIMETERS)
# Script for remote
radio.set_group(3)
def on_forever():
    if input.button_is_pressed(Button.AB):
        radio.send_value("dir", 0)
    elif input.button_is_pressed(Button.B):
        radio.send_value("dir", 2)
    elif input.button_is_pressed(Button.A):
        radio.send_value("dir", 3)
    else:
        radio.send_value("dir", 4)
basic.forever(on_forever)
@RobinBoers
Copy link
Author

RobinBoers commented Jul 21, 2021

Most of my scripts are made using MicroPython, but this one is for makecode :)

PS: If you have a 3D printer, you can print this handy controller thingie for your micro:bit remote
https://www.thingiverse.com/thing:2982246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment