Hardware Reference
In-Depth Information
try:
while True:
for d in range(10):
display.write(str(d))
time.sleep(0.5)
finally:
GPIO.cleanup()
Save and run the program. See what happens? The display should count from 0 to 9
repeatedly. Remember that on the Raspberry Pi you have to use sudo python
testDisplay2.py from a LXTerminal window.
Instead of time.sleep(0.5) in the above program, you could replace this
with a longer delay (2 seconds), or even with a raw_input() so that the
displayed pattern will stay solid while you wiggle the wires to make sure they are
all in the correct place.
CHALLENGE
Open up the seg7.py program, which is stored in the MyAdventures/anyio
folder, and follow the instructions in the file to add new symbols. See how many
of the letters of the alphabet you designed in the earlier challenge you can code
up inside this module now. What words can you write on the display, one letter
at a time? Can you write your name on the display one letter at a time? Which
letters of the alphabet are missing?
Making a Detonator
In the final project in this adventure, you will build a big red detonator button. When you
press the button there will be a countdown on the 7-segment display to give your player
time to run away from the blast, and then a huge crater will appear at the point where your
player was standing when you pressed the button. This will be a handy addition to your
toolbox as a quick way to clear some space as you move around your Minecraft world and
build things. This project introduces you to another type of GPIO, called an input, that
senses when a button is pressedā€”and you'll put your 7-segment display to good use too!
To watch a tutorial on how to build and play the detonator game, visit the
companion website at www.wiley.com/go/adventuresinminecraft and choose
the AdventureĀ 5 Video.
 
Search WWH ::




Custom Search