-
Notifications
You must be signed in to change notification settings - Fork 61
/
button.py
58 lines (40 loc) · 997 Bytes
/
button.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
46
47
48
49
50
51
52
53
54
55
56
57
58
'''
FILE NAME
button.py
1. WHAT IT DOES
Reads the status of a button using a Raspberry Pi.
2. REQUIRES
* Any Raspberry Pi
* A pushbutton
* A 10kOhm resistor
* Jumper wires
* A breadboard
3. ORIGINAL WORK
Raspberry Full stack 2015, Peter Dalmaris
4. HARDWARE
D08: Button
5. SOFTWARE
Command line terminal
Simple text editor
Libraries:
import RPi.GPIO as GPIO
6. WARNING!
None
7. CREATED
8. TYPICAL OUTPUT
Button status in the command line terminal.
// 9. COMMENTS
--
// 10. END
'''
import RPi.GPIO as GPIO ## Import GPIO Library
inPin = 8 ## Switch connected to pin 8
GPIO.setmode(GPIO.BOARD) ## Use BOARD pin numbering
GPIO.setup(inPin, GPIO.IN) ## Set pin 8 to INPUT
while True: ## Do this forever
value = GPIO.input(inPin) ## Read input from switch
if value: ## If switch is released
print "Not Pressed"
else: ## Else switch is pressed
print "Pressed"
GPIO.cleanup()