32 lines
615 B
Python
32 lines
615 B
Python
#! /usr/bin/python3
|
|
import RPi.GPIO as GPIO
|
|
from pathlib import Path
|
|
import time
|
|
|
|
class Relay:
|
|
def __init__(self, pin):
|
|
self.pin = pin
|
|
|
|
def setup(self):
|
|
GPIO.setmode(GPIO.BOARD)
|
|
GPIO.setup(self.pin, GPIO.OUT, initial=GPIO.HIGH)
|
|
|
|
def turn_on(self):
|
|
GPIO.output(self.pin, GPIO.LOW)
|
|
|
|
def turn_off(self):
|
|
GPIO.output(self.pin, GPIO.HIGH)
|
|
|
|
def teardown(self):
|
|
GPIO.cleanup(self.pin)
|
|
|
|
if __name__ == '__main__':
|
|
relay = Relay(12)
|
|
relay.setup()
|
|
relay.turn_on()
|
|
time.sleep(5)
|
|
relay.turn_off()
|
|
time.sleep(5)
|
|
relay.teardown()
|
|
|