-
Notifications
You must be signed in to change notification settings - Fork 1
/
fancontroller.py
52 lines (46 loc) · 1.38 KB
/
fancontroller.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from RPi import GPIO as gpio
from gpiozero import CPUTemperature
from threading import Event
import logging, os
from pathlib import Path
logger = logging.getLogger('test')
FORMAT = logging.Formatter('%(levelname)s: %(asctime)s, %(message)s')
path = Path('fancontroller_log', 'log.txt')
filehandler = logging.FileHandler(path, mode='a+', encoding='utf-8', delay=False)
filehandler.setFormatter(FORMAT)
logger.addHandler(filehandler)
logger.setLevel(logging.DEBUG)
os.chmod(path, 0o777)
def insertdebug(message):
logger.debug(message)
def run(newRound):
pwm = None
temp = None
try:
gpio.setmode(gpio.BCM)
gpio.setup(18, gpio.OUT)
pwm = gpio.PWM(18, 300)
pwm.start(100)
while not newRound.wait(20):
temp = CPUTemperature().temperature
#print(temp)
if temp > 75:
pwm.ChangeDutyCycle(100)
elif temp > 65:
pwm.ChangeDutyCycle(80)
elif temp > 55:
pwm.ChangeDutyCycle(70)
elif temp > 50:
pwm.ChangeDutyCycle(50)
elif temp > 45:
pwm.ChangeDutyCycle(30)
else:
pwm12.ChangeDutyCycle(0)
except Exception as e:
newRound.set()
insertdebug(e)
pwm.stop()
gpio.cleanup()
if __name__ == '__main__':
newRound = Event()
run(newRound)