# uPy - Testing GPIO on Pico Breadboard
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-01-12  Initial release

from	machine		import	Pin
import	time

# ================== Hardware definitions ======================

pin_led         = 25					# on-board green led
pins_button		= (10, 11, 12, 13)
pins_led		= ( 0,  1,  2,  3)
pin_buzzer		= 14
pins_pci		= (19, 16, 18, 17)		# MOSI, MISO, SCK and CE

# ==================== Hardware setup  =========================

led		= Pin(pin_led, Pin.OUT, value=1)
buttons	= [Pin(pin, Pin.IN, Pin.PULL_UP) for pin in pins_button]
leds	= [Pin(pin, Pin.OUT, value=0)    for pin in pins_led]
buzzer	= Pin(pin_buzzer, Pin.OUT, value=0)

# ========================= Test ===============================

# Buttons 1..4 control Leds 1..4, button 4 also operates the buzzer
def testGPIO():
    for button, led in zip(buttons, leds):
        led(button())			# led := button @ 10 Hz
    buzzer(buttons[3]())		# buzzer is Button 4


def test():
    while True:
        for _ in range(10):
            testGPIO()
            time.sleep_ms(100)
        print('*', end='')				# monitor @ 1 Hz
        led(not led())					# on-board led 0.5 Hz
              
        
test()

# ========================= End ================================
