Steady Hand / Live Wire Game & PiBrella

I’m currently writing some Pi activity packs to use at a big Scout event on Saturday. One of them uses the excellent PiBrella to allow easily accessible physical computing via the GPIO interface.

After taking the reader/coder through the basics (lights, buzzer and the big red button!) I put together an extension task to make a Steady Hand/Live Wire game. Here’s the setup and introduction

Steady Hand setup

Steady Hand description

The code they are given is shown below

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pibrella
import time
 
state = 'end'
startTime = 0
endTime = 0
touch = 0
 
while True:
 
    #start position touched
    if pibrella.input.a.read():
        if state != 'reset':
            startTime = 0
            touch = 0
            state = 'reset'
            print 'Home and reset'
 
    #copper wire touched
    elif pibrella.input.b.read():
        if state == 'started':
            print 'Touch!'
            touch += 1
            state = 'touch'
            pibrella.light.on()
 
    #end position touched
    elif pibrella.input.c.read():
        if state == 'started':
            endTime = time.time()
            state = 'end'
            print 'You made it in', endTime - startTime, 'seconds!'
            print 'You had', touch, 'touches of the wire'
 
    elif not pibrella.input.a.read():
        # we've started
        if state == 'reset':
            print 'Timer started - Good luck!'
            state = 'started'
            touch = 0
            startTime = time.time()
 
        # we've stopped touching the wire
        elif state == 'touch':
            state = 'started'
            pibrella.light.off()
 
    time.sleep(0.1)

and that’s it. If you saw me at CamJam, the one I had there was a pimped up version. It had an LCD attached to show the fastest time and lives remaining. The buzzer on the Pibrella was also used, while the LEDs counted down your three lives. But those, dear reader, are YOUR extension tasks 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.