Coder Social home page Coder Social logo

simonprickett / pi-arcade-button-led Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 9 KB

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

Home Page: https://simonprickett.dev/raspberry-pi-arcade-button-led-game/

License: MIT License

Python 100.00%
python raspberry-pi raspberrypi adafruit arcade-button led piezo-buzzer iot

pi-arcade-button-led's Introduction

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.

pi-arcade-button-led's People

Contributors

simonprickett avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.