From 37995d768d2911c04c77ea0787b783892e690027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sat, 4 Jul 2015 23:53:20 +0200 Subject: [PATCH] Add GPIO testing script --- gpio_tests/test.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 gpio_tests/test.py diff --git a/gpio_tests/test.py b/gpio_tests/test.py new file mode 100644 index 0000000..762ac2b --- /dev/null +++ b/gpio_tests/test.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +from RPi import GPIO +import time + + +# blinking function +def blink(pin): + GPIO.output(pin, GPIO.HIGH) + time.sleep(.1) + GPIO.output(pin, GPIO.LOW) + time.sleep(.1) + return + + +def test_leds(): + # to use Raspberry Pi board pin numbers + GPIO.setmode(GPIO.BOARD) + pins = [11, 12, 15] + # set up GPIO output channel + for pin in pins: + GPIO.setup(pin, GPIO.OUT) + + # blink GPIO17 50 times + for i in range(0, 50): + for pin in pins: + blink(pin) + + +def test_button(): + GPIO.setmode(GPIO.BCM) + + button = 23 + GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + while True: + GPIO.wait_for_edge(button, GPIO.RISING) + + print("Button Pressed") + + GPIO.wait_for_edge(button, GPIO.FALLING) + + print("Button Released") + + +test_button() + +GPIO.cleanup()