Approved content

The content below is provided by a partner.

aorczyk/lego-pf-transmitter 1.0.4 GitHub

Power Functions Transmitter

Control your LEGO Power Functions devices simultaneously with Micro:bit and an 940 nm emitting diode.

Features:

References:

:warning: Warning!

The light (solar :sunny: or lamp :bulb:) falling on the diode or ir receiver interferes with the signal transmission.

Command execution delay time

Every command sending to receiver is a package of five the same signals. Command execution delay time depends of the signal length (maximum length is 16ms) and light interference to the signal (which may result in the first signals not being received). It could be different each time. The maximum delay time will be if the receiver only receives the fifth signal, is around: 16*5 = 80ms + time for processing the signals.

Documentation

pfTransmitter.connectIrSenderLed

Connects infrared 940 nm emitting diode at specified analog pin.

pfTransmitter.connectIrSenderLed(AnalogPin.P0)

Parameters

pfTransmitter.setSpeed

Set the motor speed as a number.

pfTransmitter.setSpeed(1, 1, 7)

Parameters

pfTransmitter.brake

Brake then float the motor.

pfTransmitter.brake(1, 1)

Parameters

pfTransmitter.singleOutputMode

Single output mode (speed remote control). This mode is able to control: one output at a time with PWM or clear/set/toggle control pins. This mode has no timeout for lost IR on all commands except “full forward” and “full backward”. Following commands are supported:

pfTransmitter.singleOutputMode(PfChannel.Channel1, PfOutput.Red, PfSingleOutput.Forward7)

Parameters

pfTransmitter.comboDirectMode

Combo direct mode (ordinary remote control). Controlling the state of both output A and B at the same time. This mode has timeout for lost IR. Following commands are supported:

pfTransmitter.comboDirectMode(PfChannel.Channel1, PfComboDirect.Forward, PfComboDirect.Float)

Parameters

pfTransmitter.comboPWMMode

Combo PWM mode - controlling the state of both output A and B at the same time. This mode has timeout for lost IR. Following commands are supported:

pfTransmitter.comboPWMMode(PfChannel.Channel1, PfComboPWM.Forward7, PfComboPWM.Forward1)

Parameters

pfTransmitter.advancedSettings

Advanced settings.

pfTransmitter.advancedSettings(repeatCommandAfter, afterSignalPause, signalRepeatNumber)

Parameters

MakeCode Example

pfTransmitter.connectIrSenderLed(AnalogPin.P0)

input.onButtonPressed(Button.A, function() {
    pfTransmitter.singleOutputMode(PfChannel.Channel1, PfOutput.Red, PfSingleOutput.Forward7)
    pfTransmitter.singleOutputMode(PfChannel.Channel1, PfOutput.Blue, PfSingleOutput.Forward7)
})

input.onButtonPressed(Button.B, function() {
    pfTransmitter.singleOutputMode(PfChannel.Channel1, PfOutput.Red, PfSingleOutput.Float)
    pfTransmitter.singleOutputMode(PfChannel.Channel1, PfOutput.Blue, PfSingleOutput.Float)
})

Disclaimer

LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this project.

License

Copyright (C) 2021 Adam Orczyk

Licensed under the MIT License (MIT). See LICENSE file for more details.

Supported targets

PF Transmitter=github:aorczyk/lego-pf-transmitter#v1.0.4