Hardware Reference
In-Depth Information
Modify your Crafty Crossing program to set up the hardware and wait for the button
to be pressed before starting the game:
1. Import the 7-segment display module under the existing import statements:
import anyio.seg7 as display
2. Import the GPIO module for your hardware and create constants for the pins
that will be used:
On the Raspberry Pi:
import RPi.GPIO as GPIO
BUTTON = 4
LED_PINS = [10,22,25,8,7,9,11,15]
On the Arduino:
import anyio.GPIO as GPIO
BUTTON = 4
LED_PINS = [7,6,14,16,10,8,9,15]
3. Set up the hardware:
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON, GPIO.IN)
ON = False # common-anode, set to True for common cathode
display.setup(GPIO, LED_PINS, ON)
If you are using a common cathode 7-segment display (as described in
Adventure 5), use ON = True .
4. Just before the game loop, add the code to wait for the button to be pressed:
mc.postToChat("Press the button to start")
while GPIO.input(BUTTON):
time.sleep(0.1)
while not gameOver:
The program will now create the arena and the obstacles, then wait for the player
to press the button. Only when that happens will the program exit the loop, put
the player in the arena and start the game.
5. It is important to finish off your program correctly and clean up the GPIO. Add
the following code at the end of the program:
GPIO.cleanup()
6. Run the program and test the new start button.
 
Search WWH ::




Custom Search