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

leds = [ 21, 16, 19 ]

# configure as pull up - pin over 10 kOhms to 3.3 and button
# other button pin to GND
# normally, HIGH, when closed, LOW

button_pin = 26

def setup():
    GPIO.setmode(GPIO.BCM)
    for led_pin in leds:
        GPIO.setup(led_pin, GPIO.OUT)
    GPIO.setup(button_pin, 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 read_button(button):
    return GPIO.input(button_pin) 
    
def main():
        
    try:
        setup()
        led = 0
        
        while True:
            if read_button(button_pin) == GPIO.LOW:
                led_off(leds[led])
                #led += 1
                #led %= len(leds)
                led = ( led + 1 ) % len(leds)
                led_on(leds[led])
                time.sleep(0.1)
                while read_button(button_pin) == GPIO.LOW:
                    pass
    finally:
        for led in leds:
            led_off(led)
        GPIO.cleanup

main()



