https://www.bilibili.com/video/av78150577/

python3
# -*- coding: utf-8 -*-# 树莓派 根据温度自动启动或停用风扇import RPi.GPIO as GPIOimport timeFAN=14 #BCM引脚编号GPIO.setmode(GPIO.BCM)GPIO.setup(FAN,GPIO.OUT)GPIO.output(FAN,GPIO.HIGH)# 设置风扇def set_fan(value):print('设置风扇(BCM14)电平状态:',value)GPIO.output(FAN,value)passwhile True:file = open("/sys/class/thermal/thermal_zone0/temp")# 读取结果,并转换为浮点数temp = float(file.read()) / 1000# 关闭文件file.close()print("温度: %.1f" %temp)if temp>=50:set_fan(0)#低电平,为开启风扇elif temp<=46:set_fan(1)#高电平,为关闭风扇time.sleep(10)
正在学习Go语言的PHP程序员。