15.01.2016 Views

YOUR OFFICIAL RASPBERRY PI MAGAZINE

6014BX9nm

6014BX9nm

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

THE STORY TRAIN<br />

Tutorial<br />

EMBEDDING THE SENSOR SWITCHES<br />

>STEP-01<br />

Rough out the recess<br />

Drill a sequence of holes close to an<br />

open end of a length of track. Choose<br />

a drill size to match the diameter of<br />

your reed switch. Drill a blind hole to<br />

the depth of the reed switch’s diameter.<br />

The track layout<br />

The wooden train track can be laid out in many<br />

different ways, although there are only two basic<br />

topologies: a loop or single-ended. We favour the<br />

loop because it’s obvious what you need to do to<br />

drive the story on. At the end of each page of the<br />

story, you just drive the train around the track to<br />

move on to the next page. At least two switches are<br />

required: one at point A, and the other at point B.<br />

However, this is not critical at all, as long as they are<br />

separated so that only one switch can be triggered at<br />

a time. You could use more switches at other parts<br />

of the track to trigger extra sound effects if you like.<br />

We found that someone had written a program to<br />

generate all the possible track layouts for the basic<br />

Lillibo set; the code is online here:<br />

magpi.cc/1NM4vUh.<br />

The software<br />

The idea is that when the train pulls into the station,<br />

a page is produced and a sound sample is played. This<br />

page can be text, just pictures, or a mixture of both.<br />

When the page has been read and the sound sample<br />

played, the software looks for the other switch being<br />

triggered. When it sees that, a second sound effect<br />

is played and the program then looks for the station<br />

switch to be triggered before producing the next page.<br />

In this way, there’s no problem with contact bounce<br />

on the switches, nor from multiple triggering due to<br />

the carriage’s coupling magnets.<br />

>STEP-02<br />

Finish the recess<br />

Fit a router bit to the drill and join up the blind<br />

holes. Make a smooth recess so that the reed<br />

switch can sit flush with the surface of the rail.<br />

The media<br />

The electronic book consists of a number of pages,<br />

each comprising a JPEG image file and a WAV sound<br />

file. These have to be prepared in advance, and<br />

these pages are what the Story Train is presenting<br />

as the story unfolds. Older children can write their<br />

own stories and draw accompanying pictures;<br />

youngsters or a teacher can write a story or borrow<br />

one from a book. The image files can be produced in<br />

any package; for keeping it all on the Pi, however, the<br />

Inkscape application is hard to beat, especially on the<br />

faster Model 2 Pi.<br />

raspberrypi.org/magpi January 2016 55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!