Approved content
The content below is provided by a partner.
Control your LEGO Power Functions devices simultaneously with Micro:bit and an 940 nm emitting diode.
The light (solar :sunny: or lamp :bulb:) falling on the diode or ir receiver interferes with the signal transmission.
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.
Connects infrared 940 nm emitting diode at specified analog pin.
pfTransmitter.connectIrSenderLed(AnalogPin.P0)
pin
- the analog pin where ir diode is connectedSet the motor speed as a number.
pfTransmitter.setSpeed(1, 1, 7)
channel
- the channel, a number from 1
to 4
output
- the output, a number: 1
(red), 2
(blue)speed
- the speed value, a number from -7
to 7
Brake then float the motor.
pfTransmitter.brake(1, 1)
channel
- the channel, a number from 1
to 4
output
- the output, a number: 1
(red), 2
(blue)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)
channel
- the channel from 0
to 3
output
- the output: 0
(red), 1
(blue)command
- the commandCombo 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)
channel
- the channel from 0
to 3
red
- the red output commandblue
- the blue output commandCombo 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)
channel
- the channel from 0
to 3
red
- the red output commandblue
- the blue output commandAdvanced settings.
pfTransmitter.advancedSettings(repeatCommandAfter, afterSignalPause, signalRepeatNumber)
repeatCommandAfter
- the time after which combo command is repeated (ms), default: 500afterSignalPause
- the pause before sending next signal in package (ms), default: 0signalRepeatNumber
- the number of signals in package, default: 5pfTransmitter.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)
})
LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this project.
Copyright (C) 2021 Adam Orczyk
Licensed under the MIT License (MIT). See LICENSE file for more details.
PF Transmitter=github:aorczyk/lego-pf-transmitter#v1.0.4