MicroPython RC_Plus_Joycar-RC_Plus_Remote

Diese Skripte funktionieren wie die normalen Fernsteuerungsskripte. Allerdings wurden die Fahrfunktionen grundle-gend überarbeitet. Hier ist es nun möglich stufenlos die Geschwindigkeit in alle Richtungen anzupassen. Je weiter du den micro:bit in eine Richtung neigst umso schneller fährt bzw. umso enger biegt dein Joy-Car ab.

RC_Plus_Joycar.py

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.