from machine import Pin
import random
import time
from time import sleep

led1 = Pin(22, Pin.OUT)
led2 = Pin(21, Pin.OUT)
led3 = Pin(19, Pin.OUT)
led4 = Pin(18, Pin.OUT)
led5 = Pin(5, Pin.OUT)
led6 = Pin(4, Pin.OUT)
led7 = Pin(2, Pin.OUT)
gumb = Pin(27, Pin.IN, Pin.PULL_UP)

def ena():
    led4.value(1)
    time.sleep(0.5)

def dva():
    led1.value(1)
    led7.value(1)
    time.sleep(0.5)


def tri():
    led1.value(1)
    led7.value(1)
    led4.value(1)
    time.sleep(0.5)

def stir():
    led1.value(1)
    led3.value(1)
    led5.value(1)
    led7.value(1)
    time.sleep(0.5)

def pet():
    led1.value(1)
    led3.value(1)
    led4.value(1)
    led5.value(1)
    led7.value(1)
    time.sleep(0.5)

def sest():
    led1.value(1)
    led2.value(1)
    led3.value(1)
    led5.value(1)
    led6.value(1)
    led7.value(1)
    time.sleep(0.5)

def ugasn():
    led1.value(0)
    led2.value(0)
    led3.value(0)
    led4.value(0)
    led5.value(0)
    led6.value(0)
    led7.value(0)
    time.sleep(0)

while True:
    if gumb.value() == 0:
        for _ in range(9):
            rnd = random.randint(0, 6)
            if rnd == 1:
                ena()
                ugasn()
            elif rnd == 2:
                dva()
                ugasn()
            elif rnd == 3:
                tri()
                ugasn()
            elif rnd == 4:
                stir()
                ugasn()
            elif rnd == 5:
                pet()
                ugasn()
            elif rnd == 6:
                sest()
                ugasn()
        rnd = random.randint(0, 6)
        if rnd == 1:
            ena()
        elif rnd == 2:
            dva()
        elif rnd == 3:
            tri()
        elif rnd == 4:
            stir()
        elif rnd == 5:
            pet()
        elif rnd == 6:
            sest()
        print(rnd)
    time.sleep(1)
    ugasn()