An input board with 8 switches
|
The pcb lay-out is on the right and so straight forward
that I won't bother with a circuit diagram. The switches are wired so
that they connect the corresponding GPIO pin to ground, hence they
return 0 when pressed and 1 when not active. The tracks are seen
looking through the circuit board.
|
#
Switching LEDs import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) outputs=[0,1,4,17,9,10,22,21] switches=[14,15,23,24,25,8,7,11] # Set all eight lines to output for x in outputs: GPIO.setup(x,GPIO.OUT) # Make the other eight lines inputs for x in switches: GPIO.setup(x,GPIO.IN) # Turn all LEDs off for x in outputs: GPIO.output(x,0) # Test the eight switches while True: for x in switches: if x==14: button1=GPIO.input(14) if x==15: button2=GPIO.input(15) if x==23: button3=GPIO.input(23) if x==24: button4=GPIO.input(24) if x==25: button5=GPIO.input(25) if x==8: button6=GPIO.input(8) if x==7: button7=GPIO.input(7) if x==11: button8=GPIO.input(11) if button1==False: GPIO.output(0,1) if button2==False: GPIO.output(1,1) if button3==False: GPIO.output(4,1) if button4==False: GPIO.output(17,1) if button5==False: GPIO.output(21,1) if button6==False: GPIO.output(22,1) if button7==False: GPIO.output(10,1) if button8==False: GPIO.output(9,1) time.sleep(.5) # Turn all LEDs off for x in outputs: GPIO.output(x,0) |
Back to the
interface section
|