Pi Pico - 6 Buttons
Fritzing File |
from machine import Pin # GP10 - Orange Wire # GP11 - Red Wire # GP12 - Yellow Wire # GP13 - Blue Wire # GP14 - Black Wire # GP15 - Green Wire orangeButton = machine.Pin( 10, machine.Pin.IN, machine.Pin.PULL_DOWN ) redButton = machine.Pin( 11, machine.Pin.IN, machine.Pin.PULL_DOWN ) yellowButton = machine.Pin( 12, machine.Pin.IN, machine.Pin.PULL_DOWN ) blueButton = machine.Pin( 13, machine.Pin.IN, machine.Pin.PULL_DOWN ) blackButton = machine.Pin( 14, machine.Pin.IN, machine.Pin.PULL_DOWN ) greenButton = machine.Pin( 15, machine.Pin.IN, machine.Pin.PULL_DOWN ) # Software based debouncing: currOrangeButtonState = 0 prevOrangeButtonState = 0 counterOrange = 0 currRedButtonState = 0 prevRedButtonState = 0 counterRed = 0 currYellowButtonState = 0 prevYellowButtonState = 0 counterYellow = 0 currBlueButtonState = 0 prevBlueButtonState = 0 counterBlue = 0 currBlackButtonState = 0 prevBlackButtonState = 0 counterBlack = 0 currGreenButtonState = 0 prevGreenButtonState = 0 counterGreen = 0 while True: currOrangeButtonState = orangeButton.value() if ( prevOrangeButtonState == 0 ) and ( currOrangeButtonState == 1 ): counterOrange += 1 print("Orange Button Pressed!", counterOrange) prevOrangeButtonState = currOrangeButtonState currRedButtonState = redButton.value() if ( prevRedButtonState == 0 ) and ( currRedButtonState == 1 ): counterRed += 1 print("Red Button Pressed!", counterRed) prevRedButtonState = currRedButtonState currYellowButtonState = yellowButton.value() if ( prevYellowButtonState == 0 ) and ( currYellowButtonState == 1 ): counterYellow += 1 print("Yellow Button Pressed!", counterYellow) prevYellowButtonState = currYellowButtonState currBlueButtonState = blueButton.value() if ( prevBlueButtonState == 0 ) and ( currBlueButtonState == 1 ): counterBlue += 1 print("Blue Button Pressed!", counterBlue) prevBlueButtonState = currBlueButtonState currBlackButtonState = blackButton.value() if ( prevBlackButtonState == 0 ) and ( currBlackButtonState == 1 ): counterBlack += 1 print("Black Button Pressed!", counterBlack) prevBlackButtonState = currBlackButtonState currGreenButtonState = greenButton.value() if ( prevGreenButtonState == 0 ) and ( currGreenButtonState == 1 ): counterGreen += 1 print("Green Button Pressed!", counterGreen) prevGreenButtonState = currGreenButtonState