Skip to content

Demo using an Adafruit Arcade button with built in LED as both an input and output with Python for Raspberry Pi.

License

Notifications You must be signed in to change notification settings

simonprickett/pi-arcade-button-led

Repository files navigation

Raspberry Pi Arcade Button LED / Buzzer Demos

This repository contains some example code for building a Raspberry Pi project using an Adafruit LED Arcade button, a Raspberry Pi and optionally a buzzer.

Shopping List

I used the following:

LED Button Counter Demo

The first demo I build uses the arcade button and its built in LED. Whenever the button is pressed, a global variable is incremented and the LED flashes that many times. The code for this is in pi_arcade_button_led.py. This demo doesn't use the buzzer.

Click to watch a video demonstration and code walkthrough:

Video Thumbnail

LED Button Counter Demo with Buzzer

This demo is exactly the same as the above, but the buzzer also sounds every time the LED turns on. Code is in pi_arcade_button_led_buzzer.py.

LED Button / Buzzer Game

This demo works a bit differently. Again, every time the button is pressed, the LED will flash and a global counter is incremented. This time, after a random number of button presses (1-5 in the demo), the buzzer will sound.

Imagine this as a game where the person that triggers the buzzer loses or has to do a forfeit, or maybe it's like a pass the parcel game where the person that triggers the buzzer is a winner!

After the buzzer has been triggered, a new random number is chosen and the game immediately restarts.

The code for this example is in pi_arcade_button_led_buzzer_game.py.

Click to watch a video demonstration and code walkthrough:

Video Thumbnail

Running as a Service

As the Pi is stuck in a food container, and I can't access the ports etc, I can't login at the console. I don't really want to have to SSH into the Pi to start the Python code either, so I made it start at boot by creating a systemd service file for it.

This file is arcade_button_led.service. You can change which of the example code files it runs by altering the line:

ExecStart=/usr/bin/python pi_arcade_button_led.py

You may also need to update this line depending on where you cloned this repo to on your Pi:

WorkingDirectory=/home/pi/pi-arcade-button-led

I wrote a blog post on how to set up a systemd service on the Pi, the blog uses a Node.js application as an example but the same steps apply to setting up this Python code. If you'd like to learn about how to do that, you can read about it here.

About

Demo using an Adafruit Arcade button with built in LED as both an input and output with Python for Raspberry Pi.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages