I had worked out how to control my Marty with Scratch. But you quickly run out of dance routines to make it do. For more interesting programs, you need some input.


When you assemble your Marty it doesn't have any sensors connected to it. But the box does have two limit switches in it, and no instructions on what to do with them. I was trying to work out what to do to them (Attach them to the hands? Use them to detect when the case is open?) until I decided they would be useful to detect if Marty had walked into a wall. And then I noticed the feet had some perfectly sized holes (see below). So I guess that's what they're intended for! Using the supplied nuts and bolts they fit perfectly. I attached one to the front of the right foot and the other to the back of the left foot.

Marty limit switches on feet

To use them I fed the connectors through a hole in the bottom of the case and attached to the GPIO connectors on "Rick" (the name of Marty's circuit board brain). Note the colours of the wires are white=IO, red=+5V, black=GND. The front switch is on GPIO 0 and the rear switch on GPIO 1.

Connecting GPIO to Marty

Using the "GPIO input" blocks I wrote a simple program to make Marty walk in a direction until it hits a wall, then walk the other direction:

Scratch program for a pacing Marty

But it didn't work... Marty would hit the wall, and I'd see the switch trigger but it would keep walking. Then I realised it wasn't going to be quite so simple. The walk blocks take time to run so the GPIO inputs are only checked for a short time. If a switch is not being held down between the walk blocks it wont be detected. What was needed was some code to poll the switches and set some variables once they were triggered. Here is my updated program:

Scratch program for a pacing Marty (working)

Works now! Here is my Marty stuck in a pacing loop (sorry Marty!):