''' Micropython:
Klasse und Objekte - LED
'''
# pins : 15, 2, 4, 5, 18, 19, 21, 22, 23 rechts von unten nach oben
import machine, time
class LED(object):
def __init__(self, gpio_pin, aktiv):
self.aktiv = aktiv
self.pin = machine.Pin(gpio_pin, machine.Pin.OUT)
self.status = False
self.pin.value(not self.aktiv)
def status(self):
return self.status
def on(self):
self.status = True
self.pin.value(self.aktiv)
def off(self):
self.status = False
self.pin.value(not self.aktiv)
def toogle(self):
self.status = not self.status
self.pin.value(self.status)
# Erzeugen der Instanten
leds =[]
leds.append(LED(15,False))
leds.append(LED( 2,False))
leds.append(LED( 4,False))
for led in leds:
led.on()
time.sleep(2)
leds[1].off()
time.sleep(2)
leds=[]
led_pins=[15,2,4,5,18,19,21,22,23]
for pin in led_pins:
leds.append(LED(pin,False))
leds[-1].on()
time.sleep(2)
leds[-1].off()
leds[0].off()
print("Ende")