status-tower/src/main.py

37 lines
627 B
Python
Raw Normal View History

2025-07-30 03:19:44 +00:00
import RPi.GPIO as io
import time
io.setmode(io.BCM)
2025-07-30 03:24:39 +00:00
class Pin:
def __init__(self, num, off=io.HIGH):
2025-07-30 03:25:21 +00:00
self.pin = num
2025-07-30 03:25:54 +00:00
self.off_mode = off
2025-07-30 03:24:39 +00:00
2025-07-30 03:25:01 +00:00
def setup(self):
2025-07-30 03:24:39 +00:00
io.setup(self.pin, io.OUT)
2025-07-30 03:19:44 +00:00
2025-07-30 03:24:39 +00:00
def off(self):
2025-07-30 03:25:54 +00:00
io.output(self.pin, self.off_mode)
2025-07-30 03:19:44 +00:00
2025-07-30 03:24:39 +00:00
def on(self):
2025-07-30 03:25:54 +00:00
io.output(self.pin, io.LOW if self.off_mode == io.HIGH else io.HIGH)
2025-07-30 03:19:44 +00:00
2025-07-30 03:24:39 +00:00
pins = {
"red": Pin(27),
"yellow": Pin(22),
"green": Pin(24),
"blue": Pin(23),
}
2025-07-30 03:19:44 +00:00
def reset():
for name, pin in pins.items():
2025-07-30 03:24:39 +00:00
pin.setup()
pin.off()
pin.on()
2025-07-30 03:26:32 +00:00
time.sleep(1)
2025-07-30 03:24:39 +00:00
pin.off()
2025-07-30 03:19:44 +00:00
reset()