status-tower/src/main.py

40 lines
739 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:28:27 +00:00
def blink(self, blinks, blink_time_s):
for _ in range(0, blinks):
self.on()
time.sleep(blink_time_s)
self.off()
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()
2025-07-30 03:28:27 +00:00
pin.blink(3, 0.3)
2025-07-30 03:19:44 +00:00
reset()