fan controller added
parent
c097ae4605
commit
7a3f57a4b6
@ -0,0 +1,36 @@
|
|||||||
|
# controller for fan using Raspberry Pi GPIO interface
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
|
class GPIOController:
|
||||||
|
def __init__(self, board_pin):
|
||||||
|
# start processing using board numbering
|
||||||
|
# (all pins are numbered from 1 to 40)
|
||||||
|
GPIO.setmode(GPIO.BOARD)
|
||||||
|
self.board_pin = board_pin
|
||||||
|
GPIO.setup(self.board_pin, GPIO.OUT)
|
||||||
|
|
||||||
|
def enable(self):
|
||||||
|
# set high output on the pin
|
||||||
|
GPIO.output(self.board_pin, GPIO.HIGH)
|
||||||
|
|
||||||
|
def disable(self):
|
||||||
|
# set low output on the pin
|
||||||
|
GPIO.output(self.board_pin, GPIO.LOW)
|
||||||
|
|
||||||
|
def finish(self):
|
||||||
|
# drop settings of the pin
|
||||||
|
GPIO.cleanup(self.board_pin)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import time
|
||||||
|
gc = GPIOController(13)
|
||||||
|
print('testing in progress...')
|
||||||
|
for i in range(10):
|
||||||
|
gc.enable()
|
||||||
|
time.sleep(5)
|
||||||
|
gc.disable()
|
||||||
|
time.sleep(5)
|
||||||
|
gc.finish()
|
||||||
|
print('testing finished')
|
||||||
|
|
||||||
Loading…
Reference in New Issue