#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
import pygame
import random

led1 = 26
led2 = 19
led3 = 13 

button1 = 21
button2 = 16
button3 = 12

def setup():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(led1, GPIO.OUT)
    GPIO.setup(led2, GPIO.OUT)
    GPIO.setup(led3, GPIO.OUT)
    GPIO.setup(button1, GPIO.IN)
    GPIO.setup(button2, GPIO.IN)
    GPIO.setup(button3, GPIO.IN)

def led_on(led_pin):
    GPIO.output(led_pin, GPIO.HIGH)

def led_off(led_pin):
    GPIO.output(led_pin, GPIO.LOW)

def all_off(effects):
    for effect in effects:
        effect.stop()

def main():
    #rand = random.choice([led1, led2, led3])
    #print(rand)
    try:
        setup()
        pygame.init()

        effect1 = pygame.mixer.Sound('/usr/lib/libreoffice/share/gallery/sounds/laser.wav')
        effect2 = pygame.mixer.Sound('/usr/lib/libreoffice/share/gallery/sounds/space.wav')
        effect3 = pygame.mixer.Sound('/usr/lib/libreoffice/share/gallery/sounds/kling.wav')
        effects = [ effect1, effect2, effect3 ] 
        
        while True:
            if GPIO.input(button1) == GPIO.LOW:
                led_on(led1)
                all_off(effects)
                effect1.play()
            if GPIO.input(button2) == GPIO.LOW:
                all_off(effects)
                led_on(led2)
                effect2.play()
            if GPIO.input(button3) == GPIO.LOW:
                all_off(effects)
                led_on(led3)
                effect3.play()
            led_off(led1)
            led_off(led2)
            led_off(led3)
    finally:
        led_off(led1)
        led_off(led2)
        led_off(led3)
        GPIO.cleanup()

main()



