-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRPi_GPIO_Input.py
More file actions
executable file
·53 lines (39 loc) · 1.47 KB
/
RPi_GPIO_Input.py
File metadata and controls
executable file
·53 lines (39 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
#/**********************************************/
#/* Raspberry Pi GPIO Input Example in Python. */
#/* 2016-07-31 - Version 1.00 - Jason Birch. */
#/**********************************************/
import sys
import time
import datetime
import RPi.GPIO
#/****************************/
#/* USER DEFINABLE CONSTANTS */
#/****************************/
GPIO_INPUT_PIN = 14
# /*******************************************/
# /* Configure Raspberry Pi GPIO interfaces. */
#/*******************************************/
def InitGPIO():
RPi.GPIO.setmode(RPi.GPIO.BCM)
RPi.GPIO.setup(GPIO_INPUT_PIN, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP)
RPi.GPIO.add_event_detect(GPIO_INPUT_PIN, RPi.GPIO.RISING, callback=InputCallback, bouncetime=200)
# RPi.GPIO.add_event_detect(GPIO_INPUT_PIN, RPi.GPIO.FALLING, callback=InputCallback, bouncetime=200)
# /**************************************/
# /* Raspberry Pi GPIO interupt routine. */
#/**************************************/
def InputCallback(GpioPin):
Now = datetime.datetime.now()
print(Now.strftime("%Y-%m-%d %H:%M:%S") + " - GPIO: " + format(GpioPin, "00d"))
# /**************************/
# /* Main application loop. */
#/**************************/
InitGPIO()
Key = 0
while Key == 0:
time.sleep(1)
Key = sys.stdin.read(1)
# /*************************************************/
# /* Close Raspberry Pi GPIO use before finishing. */
#/*************************************************/
RPi.GPIO.cleanup()