Receiving commands from LEGO Power Functions remote controls using IR Receiver Module Iduino ST1089. Running given function when specific button is pressed or released.
- possibility to run action on RC button pressed or released
- recording commands from given channels, which could be played by extension PF Recorder
Lighting the diode and the IR receiver with sunlight ☀️ or from an ordinary light bulb 💡 may interfere with the signal reception.
Connects to the IR receiver module at the specified digital pin.
pfReceiver.connectIrReceiver(DigitalPin.P2)
pin
- the digital pin where ir receiver module is connected
Do something when a specific command is sent.
pfReceiver.onCommand(0, 0b110, 0b100, PfAction.Pressed, () => {
basic.showIcon(IconNames.Happy)
})
mode
- the mode (binary eg. 0b100)data
- the data (binary eg. 0b0101) or -1 (triggers all events)action
- the trigger action (Pressed or Released)handler
- the body code to run when the event is raised
Do something when a specific button is pressed or released on the PF speed remote control.
pfReceiver.onSpeedRCcommand(PfReceiverChannel.Channel1, PfSpeedControl.RedIncrement, PfAction.Pressed, () => {
counter += 1;
})
channel
- the channel switch 0-3button
- the buttonaction
- the trigger action (Pressed or Released)handler
- the body code to run when the event is raised
Do something when a specific state of buttons on the PF remote control is achieved.
pfReceiver.onRCcommand(PfReceiverChannel.Channel1, PfControl.Forward, PfControl.Float, PfAction.Pressed, () => {
basic.showIcon(IconNames.SmallHeart)
})
channel
- the channel switch 0-3red
- the state of the red output buttonblue
- the state of the blue output buttonaction
- the trigger action (Pressed or Released)handler
- the body code to run when the event is raised
Starts saving commands from the PF remote controls from given channels.
pfReceiver.startRecord([0]);
channels
- the array with channels number (0-3) to record with
Stops saving commands.
pfReceiver.stopRecord();
Returns recorded commands.
pfReceiver.getRecordedCommands();
pfReceiver.connectIrReceiver(DigitalPin.P2)
pfReceiver.onRCcommand(PfReceiverChannel.Channel1, PfControl.Forward, PfControl.Float, PfAction.Pressed, () => {
basic.showIcon(IconNames.Heart)
})
pfReceiver.onRCcommand(PfReceiverChannel.Channel1, PfControl.Forward, PfControl.Float, PfAction.Released, () => {
basic.clearScreen()
})
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.
- for PXT/microbit