Hi,
for those who like to play with Lego Power Functions, find attached the rPowerFunctions Library.
The library is wrapped based upon this PowerFunctions library.
It enables to control elements connected to the Lego Power Functions IR receiver, via an Arduino with an IR Transmitter.
The library has been tested on
Prototype
for those who like to play with Lego Power Functions, find attached the rPowerFunctions Library.
The library is wrapped based upon this PowerFunctions library.
It enables to control elements connected to the Lego Power Functions IR receiver, via an Arduino with an IR Transmitter.
The library has been tested on
- a MEGA with a Sunfounder IR Transmitter (connected to PWM12) controlling a motor, via IR channel 4, connected to the blue side of the IR receiver.
- a NodeMCU ESP12 Module with a Sunfounder IR Transmitter (connected to D3=GPIO0 - only this pin can be used) (same setup as 1)
B4X:
'Wiring:
' IRSend ---- Arduino Wirecolor
' GND ------- GND black
' Signal ---- PWM 12 yellow for Arduino
' Signal ---- Pin D3 yellow for NodeMCU ESP12
Sub Process_Globals
Public Serial1 As Serial
Private pf As PowerFunctions
Private Timer1 As Timer
Private Cnt As UInt = 0
Private start As Boolean = False
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
'Test MEGA
pf.Initialize(12, pf.CHANNEL4)
'Test NodeMCU
'pf.Initialize(0, pf.CHANNEL4)
Timer1.Initialize("Timer1_Tick", 1000)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
Log("Timer Tick: ", Cnt)
start = Not(start)
If start Then
pf.singlePWM(pf.BLUE, pf.PWM_FWD2)
Else
pf.singlePWM(pf.BLUE, pf.PWM_BRK)
End If
Cnt = Cnt + 1
If Cnt = 3 Then
pf.singlePWM(pf.BLUE, pf.PWM_BRK)
Timer1.Enabled = False
End If
End Sub
Prototype
Attachments
Last edited: