refactor: export functions for controlling relay

This commit is contained in:
Justin Lin
2024-03-14 13:49:24 +08:00
parent 047f86b312
commit 854b701477

View File

@@ -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()