-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtnController.py
More file actions
54 lines (41 loc) · 971 Bytes
/
Copy pathbtnController.py
File metadata and controls
54 lines (41 loc) · 971 Bytes
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
53
54
# Control an output from a button
# a button
# Jaime Balbuena
# 07/05/2020
## Libraries ##
import RPi.GPIO as GPIO
from time import sleep
## Raspberry Pi setup ##
GPIO.setmode(GPIO.BOARD) # Use the board pin numbering system
GPIO.setwarnings(False) # Disable warning at runtime
## Variables ##
LED = 3
btn = 5
ledState = False
pressed = False
btnState = True
previous = True
## Pin Initialization ##
GPIO.setup(LED, GPIO.OUT, initial = 0)
GPIO.setup(btn, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
## Functions ##
def main():
print("Code for your main function")
## MAIN ##
try:
## Code goes here ##
main()
while True:
GPIO.output(LED, GPIO.input(btn))
#btnState = GPIO.input(btn)
#if (previous != btnState and btnState == pressed):
# ledState = not ledState
# GPIO.output(LED, ledState)
#previous = btnState
#sleep(.01)
except KeyboardInterrupt:
GPIO.cleanup()
print("Keyboard interrupt. Bye Bye")
exit
finally:
print("Exiting... \n")