# region 继电器 import RPi.GPIO as GPIO import time # GPIO 代码 # 定义继电器引脚 EN_Relay = 17 def init_gpio(): """初始化GPIO设置""" GPIO.setmode(GPIO.BCM) GPIO.setup(EN_Relay, GPIO.OUT) # 初始化为高电平(关闭状态) GPIO.output(EN_Relay, GPIO.LOW) time.sleep(1) # 等待稳定 def turn_on_relay(): """打开继电器(设置为LOW)""" try: GPIO.output(EN_Relay, GPIO.HIGH) #print('Relay turned on (LOW)') except Exception as e: print(f"Error turning on relay: {e}") def turn_off_relay(): """关闭继电器(设置为HIGH)""" try: GPIO.output(EN_Relay, GPIO.LOW) #print('Relay turned off (HIGH)') except Exception as e: print(f"Error turning off relay: {e}")