-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_relay.py
More file actions
executable file
·31 lines (25 loc) · 732 Bytes
/
06_relay.py
File metadata and controls
executable file
·31 lines (25 loc) · 732 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
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
RelayPin = 11 # pin11
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
GPIO.setup(RelayPin, GPIO.OUT) # Set pin mode as output
GPIO.output(RelayPin, GPIO.HIGH)
def loop():
while True:
print '...clsoe'
GPIO.output(RelayPin, GPIO.LOW)
time.sleep(0.5)
print 'open...'
GPIO.output(RelayPin, GPIO.HIGH)
time.sleep(0.5)
def destroy():
GPIO.output(RelayPin, GPIO.HIGH)
GPIO.cleanup() # Release resource
if __name__ == '__main__': # Program start from here
setup()
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
destroy()