# Press Your Button for Raspberry Pi

## Demo Video & Overview

Remember the game show "Press Your Luck"? You can now play a version at home with this DIY Raspberry Pi project. The project uses Raspberry Pi GPIO to detect button presses for game of chance and display the game board on a TV

https://www.youtube.com/watch?v=7udusVeFsAw

JavaFX API were used to present the user interface on the Raspberry Pi's frame buffer.

Java Standard Edition for Embedded Devices was used as the implementation platform.

# Press Your Button for Raspberry Pi

## Assembly

This project uses the following hardware:

- [Raspberry Pi Model B](https://www.adafruit.com/products/998 "Raspberry Pi Model B")&nbsp;(or better)
- [Arcade Button](https://www.adafruit.com/products/1194)

![](https://cdn-learn.adafruit.com/assets/assets/000/028/807/medium800/gaming_1190-01.jpg?1448752621)

Here the hardware diagram of the arcade button.

![](https://cdn-learn.adafruit.com/assets/assets/000/028/805/medium800/gaming_bigarcadedims.jpg?1448728243)

Wiring the arcade button for input into the Raspberry Pi is as follows:

The two connections on either of the arcade button's long sides are for powering the built-in LED. These connection are seen on the bottom left, in the diagram above. Connect these to the Raspberry Pi's power and ground sources if you want the LED lit.

The connection on the very bottom is wired to Ground on the Raspberry Pi. This connection is seen on the bottom-right side off the diagram above.

The button connection that sticks out of the housing, in the same direction as the Ground connection, is connected to pin 13, on the Raspberry Pi model B Revision 2, pin header. So if looking down at the Raspberry Pi with the header in the top right corner, then the input pin connection is to 7th pin down on the left side.

Here is the wiring diagram for the project:

![](https://cdn-learn.adafruit.com/assets/assets/000/028/806/medium800/gaming_press-your-button-wiring-diagram.png?1448728329)

# Press Your Button for Raspberry Pi

## Software Prerequisites

## Java 8 and the Latest JavaFX APIs

This project requires Java 8 and specifically the JavaFX API version introduced with Java SE build 1.8.0u40. The latest version of Raspbian comes with Java 8, but unfortunately it does not include the latest JavaFX APIs.

The good news is that an overlay is available. The overlay updates the built-in JavaFX APIs to the latest.

## OpenJDK Overlay of JavaFX APIs

A good old chap, by the name of [Chris Newland](https://twitter.com/chriswhocodes "Chris Newland"), has provided the latest OpenJDK JavaFX APIs as an overlay for the Java SE Runtime Environment that ships with Raspbian.

If you want the nightly build, then head over to [http://108.61.191.178/](http://108.61.191.178/)and select a 'nightly' build from the options under **Download OpenJFX builds for Linux ARMv6 hard float (Raspberry Pi etc.)**.

Otherwise, download this local copy of the 'OpenJFX 8u40 stable for armv6hf' overlay:

&nbsp;

[openjfx-8u40-sdk-overlay-linux-armv6hf.zip](https://learn.adafruit.com/system/assets/assets//original/openjfx-8u40-sdk-overlay-linux-armv6hf.zip?1448728800)
When the download for the overlay is complete, copy it (the whole zip file) to the Raspberry Pi.

Log into the Raspberry Pi, as the pi user.

At this point, you are logged into the Raspberry Pi. Now we need to find the destination for the overlay; that is the directory of the Java Runtime on the filesystem.

On the Pi used for this project, you can see below that **java** really points to /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/bin/ **java**

```
pi@raspberrypi:~ $ which java
/usr/bin/java

pi@raspberrypi:~ $ ls -la /usr/bin/java
lrwxrwxrwx 1 root root 22 Nov 21 20:54 /usr/bin/java -&gt; /etc/alternatives/java

pi@raspberrypi:~ $ ls -la /etc/alternatives/java
lrwxrwxrwx 1 root root 51 Nov 21 20:54 /etc/alternatives/java -&gt; /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/bin/java
```

From the information above, the following is used for the destination of the OpenJDK JavaFX APIs overlay.

- /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/

Next, change directory to where the overlay ZIP file was copied.

Issue this command to perform the overlay:

```
sudo unzip openjfx-8u40-sdk-overlay-linux-armv6hf.zip -d /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/
```

Inflating messages are printed next. Answer 'A' to confirm replacement of existing files.

If no error messages are shown, then the overlay is complete :)

# Press Your Button for Raspberry Pi

## Application Installation

Download the application's executable JAR:

[press-your-button-fx-0.1-SNAPSHOT.jar](https://learn.adafruit.com/system/assets/assets//original/press-your-button-fx-0.1-SNAPSHOT.jar?1448729292)
Copy the JAR file to the Raspberry Pi.

Run the application with the following command:

```
sudo JAVAFX_DEBUG=1 java -jar press-your-button-fx-0.1-SNAPSHOT.jar
```

If everything went well, then the following is printed to the console:

```
*Provisioning GPIO.
*GPIO provisioned :)
```

# Press Your Button for Raspberry Pi

## Usage

## Background

This game is similar to "Press Your Luck", but differs in several ways.

- single or multiplayer (1-3 players)
- winner is determined by the first player to reach a pre-determined score
- Whammys only remove half the current player's score, and not the whole thing

## Playing a Game

Pressing the 'New Game' button brings up a configuration dialog for the next game.

NOTE: If you see the following error message when you click the 'New Game' button, then ensure the instructions in the 'OpenJDK Overlay' section were performed correctly.

```
Caused by: java.lang.NoClassDefFoundError: javafx/scene/control/Alert
	at org.onebeartoe.games.press.your.button.fx.FXMLController.handleNewGameButton(FXMLController.java:249)
	... 61 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.control.Alert
```

One to three players are supported.

The target score determines how high the winning score is.

To stop the score board, press either the Stop button on the application's GUI or the arcade button attached to the Rasbperry Pi.

Once a player has stopped the score board, the current player's selected panel is shown in RED lettering. If a point value (number) is shown in RED, then that amount is added to the current player's score. If a 'W' is shown in RED, then the current player loses half his score. Whammy!

After a player has taken their turn, press the 'Next Player' button to continue the game.

The first player to reach the target score wins!

## End of Run

To quit the game altogether, hit Ctrl+C on the keyboard.

# Press Your Button for Raspberry Pi

## Going Further

This project is open source. You can modify it to meet your preferences.

Some ideas to extend the application include:

- change the game sounds
- support for more than 3 players
- add an animation when a Whammy occurs
- use LEDs as indicators for winner/whammy

# Press Your Button for Raspberry Pi

## Resources

## Source Code

- [https://github.com/onebeartoe/press-your-button](https://github.com/onebeartoe/press-your-button)

## Build Server

- [https://onebeartoe.ci.cloudbees.com/job/press-your-button/](https://onebeartoe.ci.cloudbees.com/job/press-your-button/)

## JavaFX Screen Buffer on Raspberry Pi

- 
  - Basic Example - [http://javafx.steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/](http://javafx.steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/ "Basic Example")
  - Clock Example -[http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/RaspberryPiFX/raspberryfx.html](http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/RaspberryPiFX/raspberryfx.html "Clock Example")


## Featured Products

### Large Arcade Button with LED - 60mm Blue

[Large Arcade Button with LED - 60mm Blue](https://www.adafruit.com/product/1194)
BAM! This 60mm diameter arcade button is large and inviting and ready for all sorts of pressing and pushing. We've seen these on some games of skill in arcades, they're easy to mount on nearly any kind of enclosure. They're not waterproof or weatherproof, so best used indoors.<br...></br...>

In Stock
[Buy Now](https://www.adafruit.com/product/1194)
[Related Guides to the Product](https://learn.adafruit.com/products/1194/guides)
### Massive Arcade Button with LED - 100mm Red

[Massive Arcade Button with LED - 100mm Red](https://www.adafruit.com/product/1185)
OMG WATCH OUT! This 100mm diameter arcade button with a **10mm deep plastic base** is so massive and inviting it may collapse upon itself and form a black hole from which not even light can escape! Until it does, however, it ready for all sorts of pressing and pushing. Science...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1185)
[Related Guides to the Product](https://learn.adafruit.com/products/1185/guides)
### Large Arcade Button with LED - 60mm Green

[Large Arcade Button with LED - 60mm Green](https://www.adafruit.com/product/1193)
BAM! This 60mm diameter arcade button is large and inviting and ready for all sorts of pressing and pushing. We've seen these on some games of skill in arcades, they're easy to mount on nearly any kind of enclosure. They're not waterproof or weatherproof, so best used indoors.<br...></br...>

In Stock
[Buy Now](https://www.adafruit.com/product/1193)
[Related Guides to the Product](https://learn.adafruit.com/products/1193/guides)
### Raspberry Pi Model B+ 512MB RAM

[Raspberry Pi Model B+ 512MB RAM](https://www.adafruit.com/product/1914)
OMG OMG OMG, did you hear? There's a Raspberry Pi&nbsp;called the Model B+ and check it out...more USB ports, more GPIO, better power supply, four mounting holes, less sticky-out SD card! Yep, that's right, the fantastic engineers at Raspberry Pi HQ have blessed us with a new design....

In Stock
[Buy Now](https://www.adafruit.com/product/1914)
[Related Guides to the Product](https://learn.adafruit.com/products/1914/guides)
### Raspberry Pi Model B 512MB RAM

[Raspberry Pi Model B 512MB RAM](https://www.adafruit.com/product/998)
Adafruit ships the **Raspberry Pi Model B 512MB RAM** as of 10/18/2012.  
  
The Raspberry Pi® is a single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools. The Raspberry...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/998)
[Related Guides to the Product](https://learn.adafruit.com/products/998/guides)

## Related Guides

- [CLUE Dice Roller](https://learn.adafruit.com/clue-dice-roller.md)
- [Making PCB Jewelry & Art with Gingerbread and KiCad](https://learn.adafruit.com/making-pcb-art-with-gingerbread-and-kicad.md)
- [Piezo Ring Tones with Raspberry Pi](https://learn.adafruit.com/piezo-ring-tones-with-raspberry-pi.md)
- [Let’s Put LEDs in Things!](https://learn.adafruit.com/lets-put-leds-in-things.md)
- [Program in Logo on an Apple II](https://learn.adafruit.com/program-logo-on-an-apple-ii.md)
- [Adafruit's Raspberry Pi Lesson 6. Using SSH](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh.md)
- [Overwatch Prop Gun: Lucio's Blaster Pt. 2](https://learn.adafruit.com/overwatch-lucio-gun-pt-2.md)
- [Fruit Jam Sega Genesis](https://learn.adafruit.com/fruit-jam-sega-genesis.md)
- [Zelda Thunder Helm](https://learn.adafruit.com/zelda-thunder-helm.md)
- [ESP32 PlayStation Controller](https://learn.adafruit.com/esp32-playstation-controller.md)
- [Cupcade: the Raspberry Pi Micro Arcade Cabinet](https://learn.adafruit.com/cupcade-raspberry-pi-micro-mini-arcade-game-cabinet.md)
- [Adafruit's Raspberry Pi Lesson 12. Sensing Movement](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-12-sensing-movement.md)
- [Arcade Coin-Op](https://learn.adafruit.com/arcade-coin-op.md)
- [Print Your Own Circuit Boards](https://learn.adafruit.com/how-to-print-your-own-circuit-board.md)
- [Adafruit Mini I2C STEMMA QT Gamepad with seesaw](https://learn.adafruit.com/gamepad-qt.md)
