Created
September 6, 2017 12:09
-
-
Save walkure/1b86ad4d68994294be8db07653d2f561 to your computer and use it in GitHub Desktop.
Raspberry Piのファン制御スクリプト
This file contains 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
#!/usr/bin/python3 | |
import RPi.GPIO as GPIO | |
def main() -> None: | |
tmp = get_cpu_temp() | |
print("CPU temp:{0}".format(tmp)) | |
if(tmp > 60): | |
fan_control(True) | |
elif(tmp < 50): | |
fan_control(False) | |
def fan_control(active: bool) -> None: | |
GPIO.setmode(GPIO.BCM) | |
# ignore warning 'This channel is already in use.' | |
GPIO.setwarnings(False) | |
GPIO.setup(18, GPIO.OUT) | |
GPIO.output(18, active) | |
# if cleanup, output always turns off. | |
# GPIO.cleanup() | |
def get_cpu_temp() -> None: | |
with open('/sys/class/thermal/thermal_zone0/temp') as f: | |
temp = f.readline() | |
return int(temp) / 1000 | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment