[led] orangepi 2w

This commit is contained in:
IrvingGao 2024-06-09 02:37:17 +08:00
parent fa62c1b2ee
commit a808d58758
1 changed files with 17 additions and 14 deletions

View File

@ -12,9 +12,9 @@ except:
| GPIO | LED |
| -- | - - |
| 0 | 红色 |
| 1 | |
| 1 | |
| 2 | 绿色 |
| 3 | |
| 3 | |
| 4 | 白色 |
| GPIO | BUTTON |
@ -28,9 +28,9 @@ class OrangePi(BaseHardware):
super().__init__(hd_trigger, hd_detect_threshold)
self.LED_PIN_red = 0
self.LED_PIN_yellow = 1
self.LED_PIN_blue = 1
self.LED_PIN_green = 2
self.LED_PIN_blue = 3
self.LED_PIN_yellow = 3
self.LED_PIN_white = 4
self.BUTTON_PIN_1 = 6
@ -50,9 +50,9 @@ class OrangePi(BaseHardware):
wiringpi.wiringPiSetup()
# GPIO 输出模式
wiringpi.pinMode(self.LED_PIN_red, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_yellow, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_green, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_blue, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_green, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_yellow, GPIO.OUTPUT)
wiringpi.pinMode(self.LED_PIN_white, GPIO.OUTPUT)
# GPIO 输入模式
wiringpi.pinMode(self.BUTTON_PIN_1, GPIO.INPUT)
@ -80,6 +80,9 @@ class OrangePi(BaseHardware):
if press_duration > 1:
self.long_power_status = not self.long_power_status
# print(f"{datetime.now()}: long_power_status: {self.long_power_status} {self.short_power_status}")
elif press_duration > 5:
time.sleep(1) # 防止短按误触发
subprocess.Popen('sudo shutdown now', shell=True)
else:
self.short_power_status = True
# print(f"{datetime.now()}: short_power_status: {self.short_power_status} {self.long_power_status}")
@ -90,14 +93,14 @@ class OrangePi(BaseHardware):
# 更新LED状态
if self.long_power_status:
self.set_led_on('white')
self.set_led_on('green')
if self.short_power_status:
self.set_led_on('yellow')
self.set_led_on('blue')
else:
self.set_led_off('yellow')
self.set_led_off('blue')
else:
self.short_power_status = False
self.set_led_off('white')
self.set_led_off('green')
def set_led_on(self, color='red'):
@ -108,10 +111,10 @@ class OrangePi(BaseHardware):
def start_status_light(self):
for i in range(2):
self.set_led_on("white")
time.sleep(1)
self.set_led_off("white")
time.sleep(1)
self.set_led_on("green")
time.sleep(0.5)
self.set_led_off("green")
time.sleep(0.5)
if __name__ == '__main__':
orangepi = OrangePi()