# RGB Matrix Slot Machine

## Overview

https://youtu.be/oTJibE0OcBQ

![](https://cdn-learn.adafruit.com/assets/assets/000/092/181/medium800/3d_printing_hero-angle.jpg?1592258131)

## Fruit Machine

This features emojis from Circuit Playground and works just like a fruit style slot machine. The handle is 3D printed and features a print-in-place spring loaded mechanism. It actuates a small push button and triggers animations that look a lot like a slot machine.

The display is powered by an Adafruit Feather and the RGB Matrix FeatherWing. It also has a speaker and amp for playing MP3s. The FeatherWing is designed to be modular and snap fits on the back of the RGB matrix.

Using CircuitPython you can quickly show text, bitmaps, and animations on a number of different RGB Matrices. It’s designed to work with 64x32 RGB matrices.&nbsp;

## Parts
List of parts used to build this project.

- [32x64 RGB Matrix (4mm pitch)](https://www.adafruit.com/product/2278)
- [RGB Matrix FeatherWing](https://www.adafruit.com/product/3036)
- [Feather M4 Express](https://www.adafruit.com/product/3857)
- [PAM8302 Amp](https://www.adafruit.com/product/2130)
- [3W Speaker](https://www.adafruit.com/product/3968)
- [5V 4A Power Supply](https://www.adafruit.com/product/1466)
- [Slim button switch](https://www.adafruit.com/product/1489)
- [10-wire silicone ribbon cable](https://www.adafruit.com/product/3890)

![3d_printing_parts-crop.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/180/medium640/3d_printing_parts-crop.jpg?1592253203)

## Black LED Acrylic

A sheet of black LED acrylic used to diffuse the RGB LED Matrix. From their website:

> It looks like a matte black acrylic when it is not lit, but add a light behind it and watch it transform. This fantastic material has the ability to transmit light of any color.

![3d_printing_acrylic-matrix.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/157/medium640/3d_printing_acrylic-matrix.jpg?1592145131)

Black LED acrylic is used to diffuse the LEDs that are otherwise harsh and over exposed. This material features a matte finish and has the ability to transmit any color of light. That makes it perfect for bringing out the vibrance in the colors of the LEDs.

The 3D printed frame is designed with a slot on the side so it’s easy to insert a sheet of Black LED acrylic.

**Recommended Cut To Size Sheet: 257mm x 128mm (10.12in x 5.04in)**

[Black LED Acrylic from TAP Plastics](https://www.tapplastics.com/product/plastics/cut_to_size_plastic/black_led_sheet/668)
### 64x32 RGB LED Matrix - 4mm pitch

[64x32 RGB LED Matrix - 4mm pitch](https://www.adafruit.com/product/2278)
Bring a little bit of Times Square into your home with this sweet 64 x 32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked...

In Stock
[Buy Now](https://www.adafruit.com/product/2278)
[Related Guides to the Product](https://learn.adafruit.com/products/2278/guides)
![Two white hands hold out an assembled and powered on 64x32 RGB LED Matrix Panel - 4mm pitch. The matrix displays "Adafruit Industries LED MATRIX! 32x64 *RGB*"](https://cdn-shop.adafruit.com/640x480/2278-00.jpg)

Primary: 

### Adafruit RGB Matrix Featherwing Kit

[Adafruit RGB Matrix Featherwing Kit](https://www.adafruit.com/product/3036)
Ahoy! It's time to create a dazzling light up project with our new **RGB Matrix FeatherWing**. Now you can quickly and easily create projects featuring your favorite 16 or 32-pixel tall matrix boards. Using our RGB Matrix library is easy and...

In Stock
[Buy Now](https://www.adafruit.com/product/3036)
[Related Guides to the Product](https://learn.adafruit.com/products/3036/guides)
![Video of a woman with a turquoise manicure attaching a driver board to the back of a LED matrix panel. She flips the matrix panel around reveal it lit up text in rainbow colors: "Ada
fruit
32x32
*RGB* ](https://cdn-shop.adafruit.com/product-videos/640x480/3036-05.jpg)

### Adafruit Feather M4 Express - Featuring ATSAMD51

[Adafruit Feather M4 Express - Featuring ATSAMD51](https://www.adafruit.com/product/3857)
It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox, half bird, OK?) This feather is powered by our new favorite chip, the **ATSAMD51J19** -&nbsp; with...

In Stock
[Buy Now](https://www.adafruit.com/product/3857)
[Related Guides to the Product](https://learn.adafruit.com/products/3857/guides)
![Angled shot of a Adafruit Feather M4 Express. ](https://cdn-shop.adafruit.com/640x480/3857-10.jpg)

### Short Headers Kit for Feather - 12-pin + 16-pin Female Headers

[Short Headers Kit for Feather - 12-pin + 16-pin Female Headers](https://www.adafruit.com/product/2940)
These two&nbsp; **Short** &nbsp; **Female&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with any of our&nbsp;[Feather](https://www.adafruit.com/categories/777)&nbsp;boards and you're in business!

These headers are particularly cute and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2940)
[Related Guides to the Product](https://learn.adafruit.com/products/2940/guides)
![Angled shot of two stacking headers.](https://cdn-shop.adafruit.com/640x480/2940-01.jpg)

### Tactile Switch Buttons (6mm slim) x 20 pack

[Tactile Switch Buttons (6mm slim) x 20 pack](https://www.adafruit.com/product/1489)
Slim clicky momentary switches are standard input "buttons" on electronic projects. These are half the width of classic 6mm tactile switches so they line up better on a breadboard, just plug them into every-other row. These work best in a PCB but <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1489)
[Related Guides to the Product](https://learn.adafruit.com/products/1489/guides)
![2 white 6mm tactile switch buttons on a breadboard.](https://cdn-shop.adafruit.com/640x480/1489-05.jpg)

### Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long

[Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long](https://www.adafruit.com/product/3890)
For those who are fans of our silicone-covered wires, but are always looking to _up their wiring game_. We now have **Silicone Cover Ribbon cables!** These may look _a lot_ like <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3890)
[Related Guides to the Product](https://learn.adafruit.com/products/3890/guides)
![10 wire Silicone Cover Stranded-Core Ribbon Cable](https://cdn-shop.adafruit.com/640x480/3890-01.jpg)

### Adafruit Mono 2.5W Class D Audio Amplifier - PAM8302

[Adafruit Mono 2.5W Class D Audio Amplifier - PAM8302](https://www.adafruit.com/product/2130)
This super small mono amplifier is surprisingly powerful - able to deliver up to 2.5 Watts into 4-8 ohm impedance speakers. Inside the miniature chip is a class D controller, able to run from 2.0V-5.5VDC. Since the amp is a class D, its very efficient (over 90% efficient when driving an...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2130)
[Related Guides to the Product](https://learn.adafruit.com/products/2130/guides)
![Angled shot of an Adafruit Mono 2.5W Class D Audio Amplifier assembled to a speaker and white breadboard. ](https://cdn-shop.adafruit.com/640x480/2130-00.jpg)

### Speaker - 40mm Diameter - 4 Ohm 5 Watt

[Speaker - 40mm Diameter - 4 Ohm 5 Watt](https://www.adafruit.com/product/3968)
Hear the good news! This speaker&nbsp;is a great addition to any audio project where you need a&nbsp;4 Ohm impedance and 3W or less of power.

At **40mm diameter** it has a more square-ish shape, but a smaller face. Sound quality and volume are nicely sandwiched between our...

In Stock
[Buy Now](https://www.adafruit.com/product/3968)
[Related Guides to the Product](https://learn.adafruit.com/products/3968/guides)
![Angled Shot of the Speaker - 40mm Diameter - 4 Ohm 3 Watt.](https://cdn-shop.adafruit.com/640x480/3968-03.jpg)

### 5V 4A (4000mA) switching power supply - UL Listed

[5V 4A (4000mA) switching power supply - UL Listed](https://www.adafruit.com/product/1466)
Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to **4 Amps** (4000mA). 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one up at any hardware store for $1 or so,...

In Stock
[Buy Now](https://www.adafruit.com/product/1466)
[Related Guides to the Product](https://learn.adafruit.com/products/1466/guides)
![Angled shot of 5V 4A switching power supply brick with power cable.](https://cdn-shop.adafruit.com/640x480/1466-10.jpg)

### Fully Reversible Pink/Purple USB A to micro B Cable - 1m long

[Fully Reversible Pink/Purple USB A to micro B Cable - 1m long](https://www.adafruit.com/product/4111)
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also fully reversible! That's right, you will save _seconds_ a day by not having to flip the cable around.

First let's talk about the cover and over-molding. We got these...

In Stock
[Buy Now](https://www.adafruit.com/product/4111)
[Related Guides to the Product](https://learn.adafruit.com/products/4111/guides)
![Fully Reversible Pink/Purple USB A to micro B Cable](https://cdn-shop.adafruit.com/640x480/4111-02.jpg)

![](https://cdn-learn.adafruit.com/assets/assets/000/092/182/medium800/3d_printing_hero-front.jpg?1592258147)

# RGB Matrix Slot Machine

## Circuit Diagram

The diagram below provides a visual reference for wiring of the components. This diagram was created using the software package [Fritzing](http://fritzing.org/download/).

## Adafruit Library for Fritzing

Use Adafruit's Fritzing parts library to create circuit diagrams for your projects. Download the library or just grab individual parts. Get the library and parts from [GitHub - Adafruit Fritzing Parts](https://github.com/adafruit/Fritzing-Library/tree/master/parts).

![](https://cdn-learn.adafruit.com/assets/assets/000/092/134/medium800/3d_printing_circuit-diagram.jpg?1592063678)

## Wired Connections

- **A+** from PAM8302 to **A0** on RGB Matrix FeatherWing
- **A-** from PAM8302 to **GND** on PAM8302
- **Vin** from PAM8302 to **3V** on RGB Matrix FeatherWing
- **GND** from PAM8302 to **GND** on RGB Matrix FeatherWing

**Button Switch**

- Switch to **GND** on RGB Matrix FeatherWing
- Switch to **A1** on RGB Matrix FeatherWing

**Speaker**

- **Red** to (**+)Positive** on PAM8302
- **Black** to **(–)Negative** on PAM8302

## Powering

The RGB Matrix will need to be powered by a [5V 4A wall adapter](https://www.adafruit.com/product/1466). 5V USB cable is not enough to fully power the display – Glitches and artifacts are displayed when RGB matrix is only powered by USB cable.

### 5V 4A (4000mA) switching power supply - UL Listed

[5V 4A (4000mA) switching power supply - UL Listed](https://www.adafruit.com/product/1466)
Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to **4 Amps** (4000mA). 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one up at any hardware store for $1 or so,...

In Stock
[Buy Now](https://www.adafruit.com/product/1466)
[Related Guides to the Product](https://learn.adafruit.com/products/1466/guides)
![Angled shot of 5V 4A switching power supply brick with power cable.](https://cdn-shop.adafruit.com/640x480/1466-10.jpg)

# RGB Matrix Slot Machine

## 3D Printing

## Parts List

STL files for 3D printing are oriented to print "as-is" on FDM style machines. Parts are designed to 3D print without any support material. Original design source may be downloaded using the links below.

- matrix-handle.stl
- matrix-frame.stl
- speaker-holder.stl
- 2x handle-ball.stl
- foot-left.stl
- foot-right.stl

![3d_printing_3d-parts-crop.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/156/medium640/3d_printing_3d-parts-crop.jpg?1592143700)

[Download the 3D printable models from Thingiverse](https://www.thingiverse.com/thing:4462509)
[Download CAD Source Files](https://cdn-learn.adafruit.com/assets/assets/000/142/351/original/CAD.zip?1771005826)
Primary: 

Info: 

Danger: 

## Install Ball to Handle

Two hemispheres (handle-ball.stl) are joined together to form the ball of the handle. They're are press fitted over the tip of the spring-loaded handle. Domes features recesses to accommodate for the handle. Optionally use glue to bond the domes to the handle.

![3d_printing_handle-ball-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/175/medium640/3d_printing_handle-ball-install.jpg?1592228936)

## Spring–Loaded Handle

The handle features print-in-place parts that require good bed leveling and sufficient active cooling. Overhanging geometry is supported by surrounding features. No supports are required. The handle and gears are printed with loose tolerances to avoid fusing.

![3d_printing_handle-ball-installed.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/174/medium640/3d_printing_handle-ball-installed.jpg?1592228839)

## Support Material for Frame

The frame requires support material. Enable supports in the slicing software to generate scaffolding to support overhanging geometry. Use the following recommended settings:

- Support Placement: Everywhere
- Support Overhang Angle: 80
- Support Pattern: ZigZag
- Support Density: 4%
- Enable Support Brim: No
- Support Z Distance: 0.22mm
- Enable Support Interface: No

![3d_printing_cura-frame-slice.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/205/medium640/3d_printing_cura-frame-slice.jpg?1592333815)

# RGB Matrix Slot Machine

## CircuitPython on Feather M4 Express

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

The following instructions will show you how to install CircuitPython. If you've already installed CircuitPython but are looking to update it or reinstall it, the same steps work for that as well!

## Set up CircuitPython Quick Start!

Follow this quick step-by-step for super-fast Python power :)

[Download the latest version of CircuitPython for this board via CircuitPython.org](https://circuitpython.org/board/feather_m4_express/)
 **Click the link above and download the latest UF2 file.**

Download and save it to your desktop (or wherever is handy).

![arduino_compatibles_FeatherM0ExpressUF2Downloaded.png](https://cdn-learn.adafruit.com/assets/assets/000/057/318/medium640/arduino_compatibles_FeatherM0ExpressUF2Downloaded.png?1531152402)

Plug your Feather M4 into your computer using a known-good USB cable.

**A lot of people end up using charge-only USB cables and it is very frustrating! So make sure you have a USB cable you know is good for data sync.**

Double-click the **Reset** button next to the USB connector on your board, and you will see the NeoPixel RGB LED turn green. If it turns red, check the USB cable, try another USB port, etc. **Note:** The little red LED next to the USB connector will pulse red. That's ok!

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

![arduino_compatibles_FeatherM0Bootloader.jpg](https://cdn-learn.adafruit.com/assets/assets/000/057/320/medium640/arduino_compatibles_FeatherM0Bootloader.jpg?1531152568)

You will see a new disk drive appear called **FEATHERBOOT**.

&nbsp;

&nbsp;

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **FEATHERBOOT.**

![arduino_compatibles_FeatherM0FEATHERBOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/057/321/medium640/arduino_compatibles_FeatherM0FEATHERBOOT.png?1531152779)

![arduino_compatibles_FeatherM0DragCircuitPythonUF2.png](https://cdn-learn.adafruit.com/assets/assets/000/057/324/medium640/arduino_compatibles_FeatherM0DragCircuitPythonUF2.png?1531152877)

The LED will flash. Then, the **FEATHERBOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![arduino_compatibles_FeatherM0CIRCUITPY.png](https://cdn-learn.adafruit.com/assets/assets/000/057/323/medium640/arduino_compatibles_FeatherM0CIRCUITPY.png?1531152841)

## Further Information

For more detailed info on installing CircuitPython, check out [Installing CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython).

# RGB Matrix Slot Machine

## CircuitPython Libraries

## Installing or upgrading CircuitPython

You should ensure you have CircuitPython 5.3 or greater on your board. Plug your board in with a known good data + power cable (not the cheesy USB cable that comes with USB power packs, they are power only). You should see a new flash drive pop up.

If the drive is **CIRCUITPY** , then open the **boot\_out.txt** file to ensure the version number is 5.3 or greater.&nbsp;

```python
Adafruit CircuitPython 5.3.0 on 2020-04-29; Adafruit Feather M4 Express with samd51j19
```

If the version is less than 5 -or- you only get a drive named **FEATHERBOOT** then follow the [Feather M4 guide](https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51) on [installing CircuitPython](https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51/circuitpython).

## Download the Adafruit CircuitPython Library Bundle

In order to run the code, we'll need to download a few libraries. Libraries contain code to help interface with hardware a lot easier for us.

Use the&nbsp;[Feather M4 page on Installing Libraries](https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51/circuitpython-libraries)&nbsp;to get the library that matches the major version of CircuitPython you are using noted above.

The green button below links to a file containing all the libraries available for CircuitPython. To run the code for this project, we need the large number of libraries in the Required Libraries list below. Unzip the library bundle and search for the libraries. Drag and drop the files into a folder named **lib** on the **CIRCUITPY** drive (create the folder if it is not already on the Feather M4).

## Required Libraries&nbsp;

- **adafruit\_display\_text**
- **adafruit\_bitmap\_font**
- **adafruit\_imageload**

## Required Assets

- **emoji.bmp**
- **slots.mp3**

![3d_printing_code-libs.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/155/medium640/3d_printing_code-libs.jpg?1592100683)

Once we have all the files we need, a directory listing will look similar to below as far as files and directories.

## Upload Code

Click on the Download: Project Zip link below to grab the project files in a zip file directly from GitHub. Place the **code.py** file and bitmap graphics files&nbsp;onto the **CIRCUITPY** main (root) directory. The code will run properly when all of the files have been uploaded including libraries.

Use any text editor or favorite IDE to modify the code. We suggest using Mu as noted above.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/RGB_Matrix_Slot_Machine/code.py

## Double Check

See the directory listing above and double check that you have all the files listed to make this project function. If any are missing or in an incorrect directory, move them so they're in the right places.

# RGB Matrix Slot Machine

## CircuitPython Code Walkthrough

## Setup

### CircuitPython Libraries

The CircuitPython code begins by importing the libraries that are used.

```python
import random
import time

import adafruit_imageload.bmp
import audioio
import audiocore
import audiomp3
import board
import displayio
import digitalio
import framebufferio
import rgbmatrix
```

### Display setup

First, any display left over from a previous **code.py** is released. Then, the LED matrix is initialized according to its pinout. Because we want to ensure that all 3 wheels on screen are updated at the same time, we specify `auto_refresh=False`. To learn more about how to write code using the rgbmatrix module, [see the dedicated guide](https://learn.adafruit.com/rgb-led-matrices-matrix-panels-with-circuitpython/overview "RGB LED Matrices with CircuitPython").

```python
displayio.release_displays()

matrix = rgbmatrix.RGBMatrix(
    width=64, height=32, bit_depth=3,
    rgb_pins=[board.D6, board.D5, board.D9, board.D11, board.D10, board.D12],
    addr_pins=[board.A5, board.A4, board.A3, board.A2],
    clock_pin=board.D13, latch_pin=board.D0, output_enable_pin=board.D1)
display = framebufferio.FramebufferDisplay(matrix, auto_refresh=False)
```

### Additional definitions

The three states let us track whether each wheel is stopped, running, or braking.

`shuffled` lets us take an input sequence and return a new sequence with the order of the elements randomized. This will be used to put the symbols in a different order on each wheel.

`Wheel` is a class that controls the behavior of each of the 3 fruit wheels. Check out the full source code if you want to see how it works!

```python
# Each wheel can be in one of three states:
STOPPED, RUNNING, BRAKING = range(3)

# Return a duplicate of the input list in a random (shuffled) order.
def shuffled(seq):
    return sorted(seq, key=lambda _: random.random())

# The Wheel class manages the state of one wheel. "pos" is a position in
# floating point coordinates, with one 1 pixel being 1 position.
# The wheel also has a velocity (in positions
# per tick) and a state (one of the above constants)
class Wheel(displayio.TileGrid):
    def __init__(self, bitmap, pixel_shader): ...
    def step(self):
        """Update each wheel for one time step"""
        ...
    def kick(self, i):
        """Set the wheel running again, using a slight bit of randomness.
        The 'i' value makes sure the first wheel brakes first, the second
        brakes second, and the third brakes third."""
        ...
```

### Setting up the wheels

First, load the emoji bitmap into RAM memory. It is small (just a few hundred bytes), and doing this lets the display update much more fluidly than when the bitmap is in FLASH memory.

Then, create 3 wheels and put them all in a group, setting their X and Y positions so that they span the display from left to right.

Want to learn more about setting up these kinds of images, which are also known as Sprite Sheets? [There's a guide for that](https://learn.adafruit.com/circuitpython-display-support-using-displayio/sprite-sheet).

```python
# This bitmap contains the emoji we're going to use. It is assumed
# to contain 20 icons, each 20x24 pixels. This fits nicely on the 64x32
# RGB matrix display.
bitmap, palette = adafruit_imageload.load(
    "/emoji.bmp",
    bitmap=displayio.Bitmap,
    palette=displayio.Palette)

# Our fruit machine has 3 wheels, let's create them with a correct horizontal
# (x) offset and arbitrary vertical (y) offset.
g = displayio.Group()
wheels = []
for idx in range(3):
    wheel = Wheel(bitmap, palette)
    wheel.x = idx * 22
    wheel.y = -20
    g.append(wheel)
    wheels.append(wheel)
display.root_group = g
```

### Setting up the activation switch

The switch is connected to **A1** , and closing it connects it to **GND**. By enabling a pull up, the `button.value` will be `False` when it is pressed and `True` otherwise.

```python
# We want a digital input to trigger the fruit machine
button = digitalio.DigitalInOut(board.A1)
button.switch_to_input(pull=digitalio.Pull.UP)
```

### Setting up the background sounds

The speaker is connected to A0. Play casino-style noises in MP3 format. If you want to change the MP3, make sure you use a file with the following properties:

- 16000 or 22050 sample rate
- 1 channel (mono)
- 64kbit/s or lower MP3 CBR encoding

You might also like to have multiple different sounds, for instance to play when the lever is pulled and when the wheels stop. You can change to a different sound file by `open()`ing a new file and assigning it to `sample.file`. Make sure your files all match in their sample rate, channels, and encoding.

```python
mp3file = open("/slots.mp3", "rb")
sample = audiomp3.MP3Decoder(mp3file)

speaker = audioio.AudioOut(board.A0)
speaker.play(sample, loop=True)
```

## Main loop

Here's how the main loop runs:

- Refresh the screen each time through the loop
- If all the wheels are stopped, then wait for the lever to be pulled (check `button.value`) and when it is, set all the wheels in motion by `kick()`ing them
- Otherwise, let each wheel rotate a little bit by calling `step()`&nbsp;
- Go back to the top of the loop

```python
while True:
    # Refresh the dislpay (doing this manually ensures the wheels move
    # together, not at different times)
    display.refresh(minimum_frames_per_second=0, target_frames_per_second=60)

    all_stopped = all(si.state == STOPPED for si in wheels)
    if all_stopped:
        # Once everything comes to a stop, wait until the lever is pulled and
        # start everything over again. Maybe you want to check if the
        # combination is a "winner" and add a light show or something.
        while button.value:
            pass
        for idx, si in enumerate(wheels):
            si.kick(idx)

    # Otherwise, let the wheels keep spinning...
    for idx, si in enumerate(wheels):
        si.step()
```

# RGB Matrix Slot Machine

## FeatherWing Setup

## Install Feather Headers

A strip of 12-pin and 16-pin male headers are installed on to the Feather M4 Express. The headers are fitted onto the bottom of the PCB and soldered in place.

![3d_printing_feather-headers.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/154/medium640/3d_printing_feather-headers.jpg?1592089968)

## RGB Matrix FeatherWing Headers

The RGB Matrix FeatherWing includes a 2x10 socket header, a power screw-block terminal and a 2.1mm barrel jack.

![3d_printing_matrix-featherwing-headers.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/146/medium640/3d_printing_matrix-featherwing-headers.jpg?1592089750)

## Install 2x10 Socket Header

Place the 2x10 socket header onto the bottom of the RGB Matrix FeatherWing. Solder the pins in place to secure the socket header to the PCB.

![3d_printing_matrix-IDC-soldered.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/147/medium640/3d_printing_matrix-IDC-soldered.jpg?1592089772)

## Install Power Connectors

Place the screw block terminal and 2.1 barrel jack on top of the RGB FeatherWing. Solder the pins in place to secure the two power connectors.

![3d_printing_matrix-pwr-soldered.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/148/medium640/3d_printing_matrix-pwr-soldered.jpg?1592089792)

## Install Female Headers on RGB Matrix FeatherWing

Install the extra [12-pin and 16-pin short female headers](https://www.adafruit.com/product/2940) onto the top of the RGB Matrix FeatherWing. Use the row of pins that are close to the edge of the PCB.&nbsp;

![3d_printing_matrix-female-headers-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/149/medium640/3d_printing_matrix-female-headers-install.jpg?1592089828)

## Solder Female Headers

Use the Feather M4 Express to keep the headers on the RGB Matrix FeatherWing steady while soldering pins.

![3d_printing_matrix-feather-setup.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/150/medium640/3d_printing_matrix-feather-setup.jpg?1592089856)

## RGB Matrix FeatherWing Polarity Check

Match the outline of the header on the silkscreen with the outline on the RGB matrix. The notch in the center should be facing the same way. Reference the image for the correct polarity.&nbsp;

![3d_printing_featherwing-matrix-polarity.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/151/medium640/3d_printing_featherwing-matrix-polarity.jpg?1592089889)

## Install RGB Matrix FeatherWing

The RGB Matrix FeatherWing is fitted on top of the IDC shrouded header on the display. Use the IDC shrouded header that features an arrow pointing to the right.

![3d_printing_matrix-featherwing-snapon.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/152/medium640/3d_printing_matrix-featherwing-snapon.jpg?1592089927)

## Install Feather M4 Express

The Feather M4 Express is placed on top of the RGB Matrix FeatherWing with the USB port facing the 2.1mm barrel jack.

![3d_printing_feather-matrix-installed.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/153/medium640/3d_printing_feather-matrix-installed.jpg?1592089949)

# RGB Matrix Slot Machine

## Wiring

## Power Cable

The RGB Matrix includes a plug in power cable. It features two female connectors that are linked together with two male terminals. The male terminals are connected to the screw block terminals on the RGB Matrix FeatherWing. The female connect is connected to the power header on the back of the RGB Matrix display.

![3d_printing_pwr-cable.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/135/medium640/3d_printing_pwr-cable.jpg?1592080834)

## Trim Power Cable

The cable is cut and shortened to make the wiring more organized. The wires measure to 90mm in length.

![3d_printing_pwr-cable-cut.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/136/medium640/3d_printing_pwr-cable-cut.jpg?1592080849)

## Slice Power Cable

Use wire strippers to remove a bit of insulation from each wire. Tin the exposed wire using a bit of solder. Add pieces of heat shrink tubing before slicing the wires together.&nbsp;

![3d_printing_pwr-cable-tin.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/137/medium640/3d_printing_pwr-cable-tin.jpg?1592080866)

## Shortened Power Cable

The power cable is shortened and has heat shrink tubing to insulate the exposed wires. The whole cable measures 18cm in length.

![3d_printing_pwr-cable-short.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/140/medium640/3d_printing_pwr-cable-short.jpg?1592080912)

## Wire PAM8302 Audio Amp

Use a piece of silicone ribbon cable to wire the audio amplifier to the RGB Matrix FeatherWing. The cable measures 70mm in length. A 4-wire silicone ribbon cable is soldered to the A+, A-, GND and VIN pins. The speaker is soldered to the positive and negative pins on the PAM8302.

![3d_printing_amp-wired.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/138/medium640/3d_printing_amp-wired.jpg?1592080883)

## Wire Speaker

The speaker can be wired directly to the PAM8302 amp. In this project, we used a 2-pin JST extension cable so that it can be easily disconnected. The cable measures 10.6cm in length.

![3d_printing_speaker-wired.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/141/medium640/3d_printing_speaker-wired.jpg?1592080946)

## Wire Button Switch

The tactile button is wired to a lengthy piece of silicone ribbon cable. The cable measures 15.2cm in length.

![3d_printing_button-wired.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/142/medium640/3d_printing_button-wired.jpg?1592080960)

## Solder Wires to RGB Matrix FeatherWing

Make the following connections to the RGB Matrix FeatherWing.

- A+ from Amp to A0 on FeatherWing
- A- from Amp to GND on FeatherWing
- VIN from Amp to 3V on FeatherWing
- GND from Amp to GND on FeatherWing
- Button to A1 on FeatherWing
- Button to GND on FeatherWing&nbsp;

![3d_printing_rgb-featherwing-wired.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/144/medium640/3d_printing_rgb-featherwing-wired.jpg?1592080999)

## Wired RGB Matrix FeatherWing

Double check the wiring is correct.&nbsp;

![3d_printing_circuit-wired.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/145/medium640/3d_printing_circuit-wired.jpg?1592081027)

# RGB Matrix Slot Machine

## Assembly

## Connect Power Cable

Insert the negative and positive leads from the power cable to the screw block terminals. Double check the polarities are correct. Use a small flat head screw driver to tighten the terminals to secure them in place.

![3d_printing_pwr-cable-connect.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/158/medium640/3d_printing_pwr-cable-connect.jpg?1592227362)

## Circuit Wiring Review

Double check the wiring to ensure components are properly connected.&nbsp;

![3d_printing_circuit-check.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/159/medium640/3d_printing_circuit-check.jpg?1592227525)

## Secure Amp to Mount

The PAM8302 amp snap fits into the built-in holder on the mount. Orient the mounting holes with the standoffs. Insert PCB at an angle and firmly press down to install.

![3d_printing_secure-amp-mount.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/160/medium640/3d_printing_secure-amp-mount.jpg?1592227750)

## Secure Speaker to Mount

The magnet from the speaker is press fitted into the holder on the mount.&nbsp;

![3d_printing_secure-speaker-mount.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/161/medium640/3d_printing_secure-speaker-mount.jpg?1592227831)

## Install Frame to Matrix&nbsp;

Insert the RGB LED Matrix into the frame. Reference the labels on the silkscreen to determine the "upright" orientation.&nbsp;

![3d_printing_install-frame-matrix.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/163/medium640/3d_printing_install-frame-matrix.jpg?1592227930)

## Frame Slot

Check the side of the frame with the slot is facing the right side of the RGB LED Matrix.&nbsp;

![3d_printing_frame-slot.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/164/medium640/3d_printing_frame-slot.jpg?1592228006)

## Install Acrylic to Frame

The sheet of black LED acrylic is inserted and pushed through the slot on the right side of the frame. Note: The photo is showing the matrix upside down, hence on the left side of the frame.

![3d_printing_install-acrylic-frame.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/165/medium640/3d_printing_install-acrylic-frame.jpg?1592228113)

## Install Feet

Place one of the feet over the two mounting holes on the back of the RGB LED Matrix. Line up the tabs on the foot with the mounting holes.

![3d_printing_install-feet.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/166/medium640/3d_printing_install-feet.jpg?1592228194)

## Secure Feet

Use the included M3 thumb screws to secure the foot to the RGB Matrix.

![3d_printing_secure-feet.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/167/medium640/3d_printing_secure-feet.jpg?1592228256)

## Installed Feet

Proceed to secure the second foot to the RGB LED Matrix using the remaining M3 thumb screws. Reference the photo for the correct placement and orientation.

![3d_printing_installed-feet.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/168/medium640/3d_printing_installed-feet.jpg?1592228326)

## Install FeatherWing and Mount

Insert the RGB Matrix FeatherWing onto the 2x8 IDC shrouded header on the RGB Matrix. Place the mount over the second set of mounting holes to the right of the FeatherWing. Reference the photo for correct orientation and placement.

![3d_printing_installing-mount.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/169/medium640/3d_printing_installing-mount.jpg?1592228491)

## Secure Mount to RGB Matrix

Use 2x M3 x 8mm long machine screws to secure the mount to the back of the RGB matrix.

![3d_printing_secure-mount.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/170/medium640/3d_printing_secure-mount.jpg?1592228561)

## Connect Speaker to Amp

Plug in the JST connectors from the PAM8302 amp to the speaker.

![3d_printing_connect-speaker-amp.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/171/medium640/3d_printing_connect-speaker-amp.jpg?1592228631)

## Plug In Power Cable to RGB Matrix

Insert the connector from the power cable to the power port on the back of the RGB Matrix. Check to ensure the tab is fully seated over the connector.

![3d_printing_plug-power-matrix.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/172/medium640/3d_printing_plug-power-matrix.jpg?1592228697)

## Wire Management

Optionally adjust the cables so they're fitted underneath the speaker and amp mount. The mount can be used to hold the excess wiring in place.

![3d_printing_wire-manage.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/173/medium640/3d_printing_wire-manage.jpg?1592228761)

## Secure Handle to Frame

Place the handle mechanism over the right side of the frame. Line up the mounting holes. Insert and fasten 2x M3 x 10mm long machine screws through the two mounting holes on the handle. Fasten tight.

![3d_printing_secure-handle-matrix.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/176/medium640/3d_printing_secure-handle-matrix.jpg?1592229000)

## Installed Handle

Check the handle is in the correct position and can be properly pulled down and springs back up automatically.

![3d_printing_installed-handle-frame.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/177/medium640/3d_printing_installed-handle-frame.jpg?1592229052)

## Install Button to Handle

Place the button into the built-in holder on the side of the handle.

![3d_printing_install-button-handle.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/178/medium640/3d_printing_install-button-handle.jpg?1592229193)

## Test Button Handle Actuation

Pull the handle down and test out the button actuation. The lever should actuate the button and trigger the slot machine animations.

![3d_printing_test-button-handle.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/179/medium640/3d_printing_test-button-handle.jpg?1592229207)


## Featured Products

### 64x32 RGB LED Matrix - 4mm pitch

[64x32 RGB LED Matrix - 4mm pitch](https://www.adafruit.com/product/2278)
Bring a little bit of Times Square into your home with this sweet 64 x 32 square RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked...

In Stock
[Buy Now](https://www.adafruit.com/product/2278)
[Related Guides to the Product](https://learn.adafruit.com/products/2278/guides)
### Adafruit RGB Matrix Featherwing Kit

[Adafruit RGB Matrix Featherwing Kit](https://www.adafruit.com/product/3036)
Ahoy! It's time to create a dazzling light up project with our new **RGB Matrix FeatherWing**. Now you can quickly and easily create projects featuring your favorite 16 or 32-pixel tall matrix boards. Using our RGB Matrix library is easy and...

In Stock
[Buy Now](https://www.adafruit.com/product/3036)
[Related Guides to the Product](https://learn.adafruit.com/products/3036/guides)
### Adafruit Feather M4 Express - Featuring ATSAMD51

[Adafruit Feather M4 Express - Featuring ATSAMD51](https://www.adafruit.com/product/3857)
It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox, half bird, OK?) This feather is powered by our new favorite chip, the **ATSAMD51J19** -&nbsp; with...

In Stock
[Buy Now](https://www.adafruit.com/product/3857)
[Related Guides to the Product](https://learn.adafruit.com/products/3857/guides)
### Short Headers Kit for Feather - 12-pin + 16-pin Female Headers

[Short Headers Kit for Feather - 12-pin + 16-pin Female Headers](https://www.adafruit.com/product/2940)
These two&nbsp; **Short** &nbsp; **Female&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with any of our&nbsp;[Feather](https://www.adafruit.com/categories/777)&nbsp;boards and you're in business!

These headers are particularly cute and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2940)
[Related Guides to the Product](https://learn.adafruit.com/products/2940/guides)
### Tactile Switch Buttons (6mm slim) x 20 pack

[Tactile Switch Buttons (6mm slim) x 20 pack](https://www.adafruit.com/product/1489)
Slim clicky momentary switches are standard input "buttons" on electronic projects. These are half the width of classic 6mm tactile switches so they line up better on a breadboard, just plug them into every-other row. These work best in a PCB but <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1489)
[Related Guides to the Product](https://learn.adafruit.com/products/1489/guides)
### Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long

[Silicone Cover Stranded-Core Ribbon Cable - 10 Wire 1 Meter Long](https://www.adafruit.com/product/3890)
For those who are fans of our silicone-covered wires, but are always looking to _up their wiring game_. We now have **Silicone Cover Ribbon cables!** These may look _a lot_ like <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3890)
[Related Guides to the Product](https://learn.adafruit.com/products/3890/guides)
### Adafruit Mono 2.5W Class D Audio Amplifier - PAM8302

[Adafruit Mono 2.5W Class D Audio Amplifier - PAM8302](https://www.adafruit.com/product/2130)
This super small mono amplifier is surprisingly powerful - able to deliver up to 2.5 Watts into 4-8 ohm impedance speakers. Inside the miniature chip is a class D controller, able to run from 2.0V-5.5VDC. Since the amp is a class D, its very efficient (over 90% efficient when driving an...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2130)
[Related Guides to the Product](https://learn.adafruit.com/products/2130/guides)
### Speaker - 40mm Diameter - 4 Ohm 5 Watt

[Speaker - 40mm Diameter - 4 Ohm 5 Watt](https://www.adafruit.com/product/3968)
Hear the good news! This speaker&nbsp;is a great addition to any audio project where you need a&nbsp;4 Ohm impedance and 3W or less of power.

At **40mm diameter** it has a more square-ish shape, but a smaller face. Sound quality and volume are nicely sandwiched between our...

In Stock
[Buy Now](https://www.adafruit.com/product/3968)
[Related Guides to the Product](https://learn.adafruit.com/products/3968/guides)

## Related Guides

- [Adafruit Feather M4 Express](https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51.md)
- [Adafruit RGB Matrix FeatherWings](https://learn.adafruit.com/rgb-matrix-featherwing.md)
- [Adafruit PAM8302 - Mono 2.5W Class D Audio Amplifier](https://learn.adafruit.com/adafruit-pam8302-mono-2-5w-class-d-audio-amplifier.md)
- [Raspberry Pi LED Matrix Display](https://learn.adafruit.com/raspberry-pi-led-matrix-display.md)
- [eInk FeatherWing Display Stand](https://learn.adafruit.com/eink-featherwing-display-stand.md)
- [Cup o' Sound](https://learn.adafruit.com/cup-o-sound.md)
- [Matrix Portal Flow Visualizer](https://learn.adafruit.com/matrix-portal-flow-visualizer.md)
- [Esenciales para CircuitPython](https://learn.adafruit.com/esenciales-para-circuitpython.md)
- [Deco Two-Key Feather Macro Pad](https://learn.adafruit.com/deco-two-key-keypad-macropad-circuitpython-feather.md)
- [Animatronic Cosplay Wings](https://learn.adafruit.com/animatronic-cosplay-wings.md)
- [Make It Glow With Crickit](https://learn.adafruit.com/make-it-glow-with-crickit.md)
- [Glitter Positioning System](https://learn.adafruit.com/glitter-positioning-system.md)
- [Which CircuitPython Board is Right for You?](https://learn.adafruit.com/choose-your-circuitpython-board.md)
- [PiGlass](https://learn.adafruit.com/piglass-wearable-raspberry-pi-computer.md)
- [MIDI Laser Harp with Time of Flight Distance Sensors](https://learn.adafruit.com/midi-laser-harp-time-of-flight-sensors.md)
- [Ethernet for CircuitPython with Wiznet5K](https://learn.adafruit.com/ethernet-for-circuitpython.md)
- [Playa Festival Bike](https://learn.adafruit.com/playa-festival-bike.md)
- [Magic Wand](https://learn.adafruit.com/magic-wand.md)
