Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Author: Edoardo Paolo Scalafiotti <edoardo849@gmail.com>
- # Modificado por: CpA - Raspito's Family
- import os
- from time import sleep
- import signal
- import sys
- import RPi.GPIO as GPIO
- pin = 18 # The pin ID, edit here to change it
- maxTMP = 60 # Temperatura máxima donde arrancará el ventilador
- freshTMP = 45 # Temperatura de rebote, donde se apagará el ventilador
- def setup():
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(pin, GPIO.OUT)
- GPIO.setwarnings(False)
- return ()
- def getCPUtemperature():
- res = os.popen('vcgencmd measure_temp').readline()
- temp = (res.replace("temp=", "").replace("'C\n", ""))
- # print(“temp is {0}”.format(temp)) #Uncomment here for testing
- return temp
- def fanON():
- setPin(True)
- return ()
- def fanOFF():
- setPin(False)
- return ()
- def getTEMP(switch):
- CPU_temp = float(getCPUtemperature())
- # La temperatura alcanza MaxTemp
- if CPU_temp > maxTMP and not switch:
- fanON()
- return True
- # La temperatura es menor de MaxTMP, y menor de feshTMP, pero está encendido
- elif switch and CPU_temp < freshTMP:
- fanOFF()
- return False
- # Si el ventilador está encendido
- elif switch:
- return True
- else:
- return False
- def setPin(mode): # A little redundant function but useful if you want to add logging
- GPIO.output(pin, mode)
- return ()
- try:
- setup()
- ventilador_on = False
- while True:
- ventilador_on = getTEMP(ventilador_on)
- sleep(5) # Read the temperature every 5 sec, increase or decrease this limit if you want
- except KeyboardInterrupt: # trap a CTRL+C keyboard interrupt
- GPIO.cleanup() # resets all GPIO ports used by this program
Add Comment
Please, Sign In to add comment