Hardware Reference
In-Depth Information
For the Raspberry Pi:
import RPi.GPIO as GPIO
LED_PINS = [10,22,25,8,7,9,11,15] # order important
For the Arduino:
import anyio.GPIO as GPIO
LED_PINS = [7,6,14,16,10,8,9,15] # order important
3. Set the GPIO numbering mode correctly:
GPIO.setmode(GPIO.BCM)
4. Choose your type of display (I used a common anode display in my circuits):
ON = False # False=common-anode, True=common-cathode
5. Write a loop that sets all eight pins to be outputs:
for g in LED_PINS:
GPIO.setup(g, GPIO.OUT)
6. Each LED of your display will be either on or of. A really nice way to build up a
pattern for the LED display, is to store eight True or False values in a list, each
index in that list represents a different LED in the display. Remember you used
lists and indexes in Adventure 4? It's just the same as that. The list below will turn
on segments A,B,C,D,E,F,G (because the value True is used), but the decimal
point (DP) will be off because a False is stored in the last position. Index [0] in
the list is for segment A, index  [1] is for segment B, and so on.
pattern = [True, True, True, True, True, True, True,
False] # ABCDEFG (no DP)
7. Write a loop that turns on all of the pins in your chosen pattern:
for g in range(8):
if pattern[g]:
GPIO.output(LED_PINS[g], ON)
else:
GPIO.output(LED_PINS[g], not ON)
8. Now your program will have to wait for a keypress before it finishes; otherwise
all the LEDs will go off when the program stops and you won't see anything.
Using the raw_input() function will wait for you to press Enter on the key-
board before continuing to the next line of the program.:
raw_input("finished?")
9. Finally, tell the program to clean up the GPIO before the program finishes:
GPIO.cleanup()
 
Search WWH ::




Custom Search