Mario PeschJunge Tueftler
Published © CC BY-NC

Calliope Mini - Ferngesteuertes Auto

In diesem Beispiel wird mithilfe von 2 Calliope und 2 Motoren ein ferngesteuertes Auto gebaut

IntermediateFull instructions provided5 hours13,907
Calliope Mini - Ferngesteuertes Auto

Things used in this project

Hardware components

Calliope mini
Calliope mini
×2
Autofahrgestell mit Motoren
×1

Software apps and online services

pxt.calliope.cc

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schaltplan für den Anschluss von 2 Motoren an den Calliope

Code

Code für den Calliope, der die Motoren steuert

JavaScript
Just copy the text into the JavaScript-window of thePXT-Editor
let motor_rechts = 0
let motor_links = 0
let led_y_wert = 0
let led_x_wert = 0
let geschwindigkeit = 0
let richtung = 0
radio.onDataPacketReceived(({receivedString: signal, receivedNumber: wert}) => {
    if (signal == "richtung") {
        richtung = wert
    } else {
        geschwindigkeit = wert
    }
})
basic.forever(() => {
    led.unplot(led_x_wert, led_y_wert)
    led_x_wert = pins.map(
        richtung,
        -50,
        50,
        0,
        5
    )
    led_y_wert = pins.map(
        geschwindigkeit,
        0,
        100,
        5,
        0
    )
    led.plot(led_x_wert, led_y_wert)
    motor_links = geschwindigkeit + richtung
    motor_rechts = geschwindigkeit - richtung
    if (motor_links > 100) {
        motor_links = 100
    }
    if (motor_links < 0) {
        motor_links = 0
    }
    if (motor_rechts > 100) {
        motor_rechts = 100
    }
    if (motor_rechts < 0) {
        motor_rechts = 0
    }
    motors.dualMotorPower(Motor.A, motor_links)
    motors.dualMotorPower(Motor.B, motor_rechts)
})
radio.setGroup(1)
radio.setTransmitPower(7)

Code für den Calliope, der als Fernbedienung funktioniert

JavaScript
Just copy the text into the JavaScript-window of thePXT-Editor
let geschwindigkeit = 0
let y_achse = 0
let richtung = 0
let x_achse = 0
let led_y_wert = 0
let led_x_wert = 0
basic.forever(() => {
    led.unplot(led_x_wert, led_y_wert)
    x_achse = pins.map(
        input.acceleration(Dimension.X),
        -1023,
        1023,
        -50,
        50
    )
    richtung = x_achse
    y_achse = pins.map(
        input.acceleration(Dimension.Y),
        1023,
        -1023,
        0,
        100
    )
    geschwindigkeit = y_achse
    led_x_wert = pins.map(
        richtung,
        -50,
        50,
        0,
        5
    )
    led_y_wert = pins.map(
        geschwindigkeit,
        0,
        100,
        5,
        0
    )
    led.plot(led_x_wert, led_y_wert)
    radio.sendValue("geschwindigkeit", geschwindigkeit)
    radio.sendValue("richtung", richtung)
})
radio.setGroup(1)
radio.setTransmitPower(7)

Motortest

JavaScript
Code um die Motoren am Auto zu testen. 1 Sek. nur Motor A an, 1 Sek. nur Motor B an, 1 Sek. beide Motoren aus.
basic.forever(() => {
    motors.dualMotorPower(Motor.A, 100)
    motors.dualMotorPower(Motor.B, 0)
    basic.pause(1000)
    motors.dualMotorPower(Motor.A, 0)
    motors.dualMotorPower(Motor.B, 100)
    basic.pause(1000)
    motors.dualMotorPower(Motor.A, 0)
    motors.dualMotorPower(Motor.B, 0)
    basic.pause(1000)
})

Credits

Mario Pesch

Mario Pesch

0 projects • 4 followers
Junge Tueftler

Junge Tueftler

2 projects • 9 followers
Junge Tüftler offers children a playful access to electronics and programming and provides them with the right tools to create the world of tomorrow.

Comments