Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Wednesday, 28 September 2016

Lego IR "train" controller

Just a quick update on the previous post where we used the Lego IR remote to control and Arduino. I've not got my hands on a Lego "train" controller which has two dials and two buttons. Pointing one of those at an Arduino with the IR receiver attached, produces a fairly simple set of codes.

The Left dial generates 100 and 101 as its turned in each direction, while right dial generates 116/117. When used with the regular IR receiver these mean speed up/slow down on the red and blue channels but you can use them in your code to mean anything you like. Each turn will generate a burst of codes, so you're likely to receive several at a time. This is intended to make sure that the code actually gets through. You might need to ignore repeats of a code if they arrive very close together, as its not multiple turns, but just multiple signals.

The left button generates 72,  while the right button generates 88. Somewhat surprisingly pressing both butts at the same time generates 31, which to the Lego decoder means brake both motors. The numbers don't appear to make sense as 31 is a code to control both motors, while 72/88 are codes to control individual motors so are sent in a very different way.

Unlike the regular Lego remote, the codes are never combined (except for 72+88=31), so if you press and hold a button, then turn a dual, you can no longer detect if the button is pressed. Turning both dials at once, results in both sets of messages being sent, rather than just a combined signal as per the regular remote.

Channels (1-4) work report in the irProtocal variable, so you can use up to four remotes at a time!

No comments:

Post a comment