Created
October 15, 2020 02:44
-
-
Save stuartsoft/fe02486d9dd9e49d929e5227fa88767c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import gpiozero | |
fan = gpiozero.LED(14) | |
fan.off() | |
fanState = False | |
while True: | |
currentTemp = gpiozero.CPUTemperature().temperature | |
if fanState == 1 and currentTemp <= 40: | |
print("turning fan off") | |
fanState = False | |
elif fanState == 0 and currentTemp >= 45: | |
print("turning fan on") | |
fanState = True | |
fan.value = fanState | |
print("CPU is " + str(currentTemp) + "C Fan state is " + str(fan.value)) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ python rpi_fan.py &
to run in the background, so you can keep it running after disconnecting from ssh.