-6
我做了一段代碼,用於獲取我的rpi的cpu temp,並且如果它在GPIO端口7上發送信號的時間超過60 C,並且發送信號的時間不超過60 C端口上,但我得到這個錯誤:定義的Python無效語法
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())
'try'必須有一個'except'反斜槓... –
在你的try塊後加上'except:pass'。 –
您需要在函數 – user3764893