Update to use OOP

This commit is contained in:
Garrett Mills 2025-07-29 22:24:39 -05:00
parent 6e2d01ab50
commit 23f090e811

View File

@ -3,36 +3,34 @@ import time
io.setmode(io.BCM)
class Pin:
def __init__(self, num, off=io.HIGH):
self.num = num
self.off = off
def setup():
io.setup(self.pin, io.OUT)
def off(self):
io.output(self.pin, self.off)
def on(self):
io.output(self.pin, io.LOW if self.off == io.HIGH else io.HIGH)
pins = {
"red": {
"pin": 27,
"off": io.HIGH,
},
"yellow": {
"pin": 22,
"off": io.HIGH,
},
"green": {
"pin": 24,
"off": io.HIGH,
},
"blue": {
"pin": 23,
"off": io.HIGH,
},
"red": Pin(27),
"yellow": Pin(22),
"green": Pin(24),
"blue": Pin(23),
}
def off(pin):
return pin["off"]
def on(pin):
return io.LOW if pin["off"] == io.HIGH else io.LOW
def reset():
for name, pin in pins.items():
io.setup(pin["pin"], io.OUT)
io.output(pin["pin"], off(pin))
pin.setup()
pin.off()
pin.on()
time.sleep(2)
pin.off()
reset()