Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5103

Other projects • Re: Arcade Ticket Payout test

$
0
0

Code:

# Import Required Librariesimport RPi.GPIO as GPIOimport time# define the GPIO pin connected to the buttonBUTTON_PIN = 16button_counts = {}# Initialiation and Setup# Perform one-time setup tasks hereGPIO.setmode(GPIO.BCM)# Define the GPIO pin for the ledLED_PIN = 17 # Use GPIO pin 17# Set up the LED Pin as an outputGPIO.setup(LED_PIN, GPIO.OUT)# Initialize the pushbutton pin as an input with a pull-up resistor# The pull-up input pin will be HIGH when the switch is open and Low when the switch is closed.GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)# Variable to keep track of the previous button stateprev_button_state = GPIO.input(BUTTON_PIN)try:    # Main Loop    while True:        # Main code logic goes here        # Turn on the LED        GPIO.output(LED_PIN, GPIO.HIGH)                # Read the state of the switch/button        button_state = GPIO.input(BUTTON_PIN)                # Check if the button state has changed (press or release event)        if button_state != prev_button_state:            if button_state == GPIO.LOW: # Button is pressed                print("The button is pressed!")            else: # Button is released                print("The button is released!")                            # Update the previous button state            prev_button_state = button_state                    if button_counts == 15:            break            while False:        # Turn off the LED        GPIO.output(LED_PIN, GPIO.LOW)         except KeyboardInterrupt:    # Handle Crtl+c interruption    print ("\nExiting the program.")    GPIO.cleanup() #Clean up the GPIO
Ok so i have compiled some code. I am working off a breadboard with led and a photosensor right now. I am using the photosensor as the button. I am wanting to stop loop after 15 button presses and turn off the LED. I will also add in later a button start which would be the "coin up" of the "game" at this time i am not able to turn off the led it just keeps reading the button press.

Statistics: Posted by Walking4 — Fri Aug 16, 2024 5:08 pm



Viewing all articles
Browse latest Browse all 5103

Trending Articles