15.01.2016 Views

YOUR OFFICIAL RASPBERRY PI MAGAZINE

6014BX9nm

6014BX9nm

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tutorial<br />

STEP BY STEP<br />

PROGRAM<br />

TONY GOODHEW<br />

Taught programming since 1967<br />

(IBM 1130 with FORTRAN IV). BBC<br />

Micro teacher trainer, now using<br />

Raspberry Pi and Arduino.<br />

CODEBUG<br />

WITH PYTHON 3<br />

You’ll<br />

Need<br />

> CodeBug<br />

magpi.cc/<br />

1MeIyfA<br />

> USB Micro B<br />

cable (included)<br />

> Python libraries:<br />

python3-serial<br />

& python3-<br />

codebug-tether<br />

> CodeBug script:<br />

codebug-tether.<br />

cbg<br />

magpi.cc/<br />

1MeIBYR<br />

Move on from Blocky programming and control<br />

your CodeBug with all the power of Python…<br />

T<br />

he CodeBug is simple to set up and start<br />

programming with the Scratch-like Blocky<br />

interface on the website. Once you have<br />

mastered this, you'll probably want to move on to the<br />

next stage and take full control with a more powerful<br />

language like Python 3. This allows you to include<br />

more ambitious data structures, such as lists and<br />

tuples, and build larger projects with procedures.<br />

Your expert started to wonder how good a game you<br />

could build with just a square of 25 LEDs and a switch.<br />

This is his first attempt.<br />

>STEP-01<br />

Game rules<br />

We need a simple game in which you press a button<br />

when a target is in a certain position. Back in the late<br />

1970s, your expert used to set a ‘Zap the Rat’ game as<br />

homework while teaching Commodore PET or Ohio<br />

Scientific Basic. You have to click a button as a moving<br />

‘rat’ target passes a certain ‘zapping point’ on a<br />

circuit. In this version, the speed increases each time<br />

you successfully hit a rat, and you need to hit three<br />

rats with as few attempts as possible. It would be nice<br />

to display the hits while the game is running, and a<br />

final score to show how many times you missed the<br />

target. Can all of this be fitted on a 5×5 LED display?<br />

Tethered with a<br />

Micro USB cable<br />

This is the zap position<br />

Above This shows the rat at (4,0), the zap<br />

position marker, and hits counter at two zaps<br />

48 January 2016<br />

raspberrypi.org/magpi

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

Saved successfully!

Ooh no, something went wrong!