Untitled

 avatar
unknown
plain_text
a year ago
4.7 kB
4
Indexable
import time

# Suponha que LED_PINS seja uma lista definida anteriormente com as portas GPIO dos LEDs
LED_PINS = [17, 18, 22, 23, 24, 25, 27, 28]

def controla_leds():
    try:
        while True:
            # Sequência de operações conforme o padrão especificado
            
            # 0:01.261 (liga o Led1 e Led2, durante 2 segundos)
            liga_leds([LED_PINS[0], LED_PINS[1]])
            time.sleep(2)
            
            # 0:04.356 (liga o Led3, durante 2 segundos)
            liga_leds([LED_PINS[2]])
            time.sleep(2)
            
            # 0:07.681 (liga o Led4, durante 2 segundos)
            liga_leds([LED_PINS[3]])
            time.sleep(2)
            
            # 0:10.891 (liga o Led5 e Led6, durante 2 segundos)
            liga_leds([LED_PINS[4], LED_PINS[5]])
            time.sleep(2)
            
            # 0:14.216 (liga o Led7 e Led8, durante 2 segundos) OU (liga o Led1 e Led2, durante 2 segundos)
            liga_leds([LED_PINS[6], LED_PINS[7]])
            time.sleep(2)
            
            # 0:17.509 (liga o Led3, durante 2 segundos)
            liga_leds([LED_PINS[2]])
            time.sleep(2)
            
            # 0:20.708 (liga a lâmpada, durante 2 segundos) - Suponha que a lâmpada seja representada por um LED ou outro dispositivo
            liga_leds([lampada_pin])
            time.sleep(2)
            
            # 0:24.052 (liga o Led4, durante 2 segundos)
            liga_leds([LED_PINS[3]])
            time.sleep(2)
            
            # 0:27.286 (liga o Led5 e Led6, durante 2 segundos)
            liga_leds([LED_PINS[4], LED_PINS[5]])
            time.sleep(2)
            
            # 0:30.564 (liga o Led4, durante 2 segundos)
            liga_leds([LED_PINS[3]])
            time.sleep(2)
            
            # 0:33.821 (liga a lâmpada, durante 2 segundos)
            liga_leds([lampada_pin])
            time.sleep(2)
            
            # 0:37.031 (liga o Led4, durante 2 segundos)
            liga_leds([LED_PINS[3]])
            time.sleep(2)
            
            # 0:40.356 (liga o Led5 e Led6, durante 2 segundos)
            liga_leds([LED_PINS[4], LED_PINS[5]])
            time.sleep(2)
            
            # 0:43.681 (liga o Led4, durante 2 segundos)
            liga_leds([LED_PINS[3]])
            time.sleep(2)
            
            # 0:46.891 (liga a lâmpada, durante 2 segundos)
            liga_leds([lampada_pin])
            time.sleep(2)
            
            # 0:50.216 (liga o Led7 e Led8, durante 2 segundos) OU (liga o Led1 e Led2, durante 2 segundos)
            liga_leds([LED_PINS[6], LED_PINS[7]])
            time.sleep(2)
            
            # 0:53.426 (liga o Led3, durante 2 segundos)
            liga_leds([LED_PINS[2]])
            time.sleep(2)
            
            # 0:56.642 (liga o Led5 e Led6, durante 2 segundos)
            liga_leds([LED_PINS[4], LED_PINS[5]])
            time.sleep(2)
            
            # 1:00.075 (liga a lâmpada, durante 2 segundos)
            liga_leds([lampada_pin])
            time.sleep(2)
            
            # 1:03.285 (liga o Led7 e Led8, durante 2 segundos) OU (liga o Led1 e Led2, durante 2 segundos)
            liga_leds([LED_PINS[6], LED_PINS[7]])
            time.sleep(2)
            
            # 1:06.496 (liga o Led5 e Led6, durante 2 segundos)
            liga_leds([LED_PINS[4], LED_PINS[5]])
            time.sleep(2)
            
            # 1:09.706 (liga o Led3, durante 2 segundos)
            liga_leds([LED_PINS[2]])
            time.sleep(2)
            
            # 1:13.031 (liga o Led1 e Led2, durante 2 segundos)
            liga_leds([LED_PINS[0], LED_PINS[1]])
            time.sleep(2)
            
            # 1:16.355 (liga o Led5 e Led6, durante 2 segundos)
            liga_leds([LED_PINS[4], LED_PINS[5]])
            time.sleep(2)
            
            # Pausa de 5 segundos
            time.sleep(5)
    
    except KeyboardInterrupt:
        print("Interrupção pelo usuário")

def liga_leds(pins):
    for pin in pins:
        # Ligar o LED
        print(f'Ligando LED {pin}')
        # GPIO.output(pin, GPIO.HIGH)  # Comentei essa linha para testar o código
        
    # Manter os LEDs ligados por 2 segundos
    time.sleep(2)
    
    for pin in pins:
        # Desligar o LED
        print(f'Desligando LED {pin}')
        # GPIO.output(pin, GPIO.LOW)  # Comentei essa linha para testar o código

# Para testar a função
controla_leds()
Editor is loading...
Leave a Comment