You can control LEGO Power Function using Scrach as you can see on this video.

To achieve this follow these few steps:

  • Download S4A (Scratch For Arduino)
  • Download modified S4A firmware - 09 S4A LEGO IR Power Function.zip - I found it on this site.
  • Optionally: to test if your Arduino board work witch S4A you can check original S4AFirmware.
  • Extract files and copy three of them to directory named S4AFirmware14_LEGO_PF_IR:
    • S4AFirmware14_LEGO_PF_IR.ino
    • PowerFunctions.cpp
    • PowerFunctions.h
  • I've changed pin from D5 to D12 (it depends on hardware)

    int IR_pin = 12; // LEGO PF IR channel
    
  • Use Arduino (or similar software) tu compile and upload S4AFirmware14_LEGO_PF_IR.ino (during uploading you have to close S4A because it can interrupt communication)
  • Connect IR diode to pin (D12 in my case) - I've prepared simple board (in KiCAD) for Arduino Nano

Now You can make your first program:

it is a bit tricky: analog 5 mean "RED" channel and analog 6 mean "BLUE" one, values are

  • 0 - float
  • 1-7 forward (1-low, 7-fast)
  • 100 - break
  • 101-107 - reverse (101-low, 107-fast)

So this program does: FWD, wait 1s, Stop, wait 1s, REV, wait 1s, Stop, wait 1s for both channels/engines

Have fun!

Ten kto umie pisze kod, ten kto nie umie pisze książki..., albo blog.

Pon Wt Śr Czw Pt So N
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28        
eZ Publish™ copyright © 1999-2024 eZ Systems AS