-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbpress2.py
45 lines (33 loc) · 1.01 KB
/
bpress2.py
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
#
# Copyright (C) 2016 David Brookshire <[email protected]>
#
import time
import RPi.GPIO as GPIO
def main():
# tell the GPIO module that we want to use the
# chip's pin numbering scheme
GPIO.setmode(GPIO.BCM)
# setup pin 25 as an output
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.OUT)
# GPIO.setup(25,GPIO.OUT)
# GPIO.output(25,True)
while True:
pressed = not GPIO.input(18)
if pressed:
# the button is being pressed, so turn on the green LED
# and turn off the red LED
GPIO.output(17,True)
# GPIO.output(25,False)
print "button true"
else:
# the button isn't being pressed, so turn off the green LED
# and turn on the red LED
GPIO.output(17,False)
# GPIO.output(25,True)
print "button false"
time.sleep(0.1)
print "button pushed"
GPIO.cleanup()
if __name__=="__main__":
main()