MicroPython RC_Plus_Joycar-RC_Plus_Remote

These scripts work like the normal remote control scripts. However, the driving functions have been fundamentally revised. It is now possible to adjust the speed in all directions. The more you tilt the micro:bit in one direction the faster your Joy-Car will drive or the tighter your Joy-Car will turn.

RC_Plus_Remote.py

from microbit import *
import radio

radio.on()

pwm = (0, 0, 0, 0)
xy = (0, 0)

def scale(num, in_min, in_max, out_min, out_max):
    return((num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min)

def fetch_data():
    xyz = accelerometer.get_values()
    x = 0
    y = 0

    if xyz[0] > 300:
        x = round(scale(xyz[0], 300, 1000, 0, 1),2)
    elif xyz[0] < -300:
        x = round(scale(xyz[0], -300, -1000, 0, -1),2)

    if  xyz[1] < -300:
        y = round(scale(xyz[1], -300, -1000, 0, -255))
    elif xyz[1] > 300:
        y = round(scale(xyz[1], 300, 1000, 0, 255))

    if x > 1:
        x = 1
    elif x < -1:
        x = -1

    if y > 255:
        y = 255
    elif y < -255:
        y = -255

    return x, y

def drive(xy):

def send_data():
    radio.send(pwm)
while True:
    xy = fetch_data()
    print(xy)


    sleep(1000)

Achtung!

Ihr Webbrowser ist veraltet. Wechseln Sie jetzt zu einem aktuellen Browser für mehr Sicherheit, Geschwindigkeit und den besten Komfort auf dieser Seite.