|
from gpiozero import LED, Button
|
|
from time import sleep
|
|
|
|
|
|
# Print introductory information
|
|
print("-------------------------------------------------")
|
|
print("Hello! Welcome to the Capstone RPi GPIO test program.")
|
|
print("This program is meant to be used with the Design Lab MCU tester.")
|
|
print("To get a pinout of the Raspberry Pi, run the command \"pinout\" in " +
|
|
"the terminal.")
|
|
print("Plug a 3.3V power pin into the tester's VCC header.")
|
|
print("Plug a ground pin into the tester's GND header.")
|
|
print("Plug the pin to be tested into the tester's pin header.")
|
|
print("Turn the potentiometer all the way counter-clockwise.")
|
|
print("Note that to test say GPIO4, or pin 7, use the number 4 in this" +
|
|
" program.")
|
|
print("Once you are satisfied, Ctrl-C to exit out of this script\n")
|
|
|
|
# Ctrl-C to exit
|
|
while True:
|
|
# Does user want to test input or output?
|
|
print("Are you testing input or output?")
|
|
print("Please type \"input\" or \"output\": ")
|
|
while True:
|
|
option = input()
|
|
if option == "input" or option == "output":
|
|
break
|
|
else:
|
|
print("Please type \"input\" or \"output\"")
|
|
|
|
# Testing lighting an LED
|
|
if option == "output":
|
|
print("Please toggle the toggle switch to Output.")
|
|
|
|
# Get pin number that user wants to test
|
|
while True:
|
|
output_pin = int(input("What is the pin you're testing? "))
|
|
if output_pin >= 1 and output_pin <= 27:
|
|
break
|
|
else:
|
|
print("Invalid pin number!")
|
|
|
|
# Set up LED object
|
|
led = LED(output_pin)
|
|
|
|
# Blink LED 10 times
|
|
print(f"Blinking LED connected to pin {output_pin}")
|
|
print("Ctrl-C to exit")
|
|
for i in range(5):
|
|
led.on()
|
|
sleep(1)
|
|
led.off()
|
|
sleep(1)
|
|
# Testing reading a button
|
|
elif option == "input":
|
|
print("Please toggle the toggle switch to Input.")
|
|
print("Please also turn the potentiometer all the way CCW.")
|
|
|
|
# Get pin number that user wants to test
|
|
while True:
|
|
input_pin = int(input("What is the pin you want to test? "))
|
|
# There are only 27 GPIOs
|
|
if input_pin >= 1 and input_pin <= 27:
|
|
break
|
|
else:
|
|
print("Invalid pin number!")
|
|
|
|
# Set up button object
|
|
button = Button(input_pin)
|
|
|
|
print("Every half a second, if the button is pressed, the program " +
|
|
"will say so!")
|
|
# Press the button
|
|
for i in range(10):
|
|
if button.value() == 1:
|
|
print("Button is pressed!")
|
|
sleep(0.5)
|