refactor: export functions for controlling relay
This commit is contained in:
31
relay.py
31
relay.py
@@ -6,17 +6,24 @@ import time
|
||||
# Config those variables
|
||||
PIN = 12
|
||||
|
||||
def main():
|
||||
time.sleep(5)
|
||||
GPIO.output(PIN, GPIO.LOW)
|
||||
time.sleep(5)
|
||||
GPIO.output(PIN, GPIO.HIGH)
|
||||
time.sleep(5)
|
||||
GPIO.output(PIN, GPIO.LOW)
|
||||
time.sleep(5)
|
||||
GPIO.cleanup()
|
||||
|
||||
if __name__ == '__main__':
|
||||
def setup():
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
GPIO.setup(PIN, GPIO.OUT, initial=GPIO.HIGH)
|
||||
main()
|
||||
|
||||
def turnOn():
|
||||
GPIO.output(PIN, GPIO.LOW)
|
||||
|
||||
def turnOff():
|
||||
GPIO.output(PIN, GPIO.HIGH)
|
||||
|
||||
def tearDown():
|
||||
GPIO.cleanup(PIN)
|
||||
|
||||
if __name__ == '__main__':
|
||||
setup()
|
||||
turnOn()
|
||||
time.sleep(5)
|
||||
turnOff()
|
||||
time.sleep(5)
|
||||
tearDown()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user