我制作了一段代码,用于获取rpi的CPU温度,如果它超过60 C,则在GPIO端口7上发送信号,如果它不超过60 C则不在端口上发送信号但我收到此错误:
File "tempgate.py", line 17
def FanController(CPU_temp) :
^
SyntaxError: invalid syntax
文件是:
#Module import and variables
import getinfo
import RPi.GPIO as GPIO
import time
import atexit
import datetime
CPU_temp = getinfo.getCPUtemperature
#Start info
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print("[LOG] [" + st + "] Program has started")
#Setup and definitions
try:
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
def FanController(CPU_temp) :
CPU_temp = int(float(CPU_temp))
print(CPU_temp)
if(int(CPU_temp) > int(60)) :
GPIO.setup(7, GPIO.OUT)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print("[LOG] [" + st + "] Fan is now on")
time.sleep(5)
else :
GPIO.setup(7, GPIO.IN)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print("[LOG] [" + st + "] Fan is now off")
time.sleep(5)
#main app
while True :
CPU_temp = getinfo.getCPUtemperature()
print("[LOG] [" + st + "] Cpu CPU_temp is: " + CPU_temp)
FanController(CPU_temp)
GPIO.cleanup()
atexit.register(GPIO.cleanup())
答案 0 :(得分:0)
您有一个与try...
无法匹配的未公开except
块。