Slot Machine

by valintadel in Circuits > Arduino

63 Views, 1 Favorites, 0 Comments

Slot Machine

WhatsApp-kép, 2025-01-20, 16.23.54_fa445b07.jpg
WhatsApp-kép, 2025-01-20, 16.23.53_f7d79ca8.jpg

This project was developed for 'Electrónica Creativa' (Creative Electronics), a BEng Electronic Engineering 4th year module at the University of Malaga, School of Telecommunication (http://etsit.uma.es/)


This project combines hardware and software to create an interactive Sloth Machine. The hardware includes buttons, screens, and electronic circuits, all controlled by an Arduino board. The software manages inputs, outputs, and system functionality, ensuring a seamless user experience.

We outline key steps for assembling the components and programming the system, demonstrating how creativity and engineering can bring innovative ideas to life.

Supplies

Electronics:

  1. Arduino UNO
  2. Power supply: AC/DC adaptor model: JCY-1200
  3. Input: AC100-249C~; Output: 12 V
  4. Main screen: Hiletgo TFT Screen (ILI9341)
  5. Credit screen: 1602A LCD Display
  6. 5 x 3.3k ohm resistor
  7. 5 x 2.2k ohm resistor
  8. potentiometer (10k ohm)
  9. Breadboard
  10. Jumper wires
  11. Buttons

Software and Tools:

  1. Arduino IDE
  2. Soldering Iron
  3. 3D Printer
  4. Glue gun

Make the Hardware Prototype

WhatsApp-kép, 2025-01-21, 21.36.33_d8dfa60c.jpg
WhatsApp-kép, 2025-01-21, 21.36.45_7e231b0c.jpg
WhatsApp-kép, 2025-01-21, 21.36.19_256b586e.jpg

First, we made a prototype that we can later modify.

1. Main Screen (Hiletgo TFT Screen, more information here), for it to work is connected to the current divider with 2.2k and 3.3k resistors to the Arduino Uno.

2. Credit Screen (1602A LCD Display, more information here), connected normally with a potentiometer of 10k for contrast changes.

3. Buttons are connected on the analogue pins of the Arduino: yellow, red, green, and black with the use of: the play button, add funds, increase the bet, decrease the bet.


For pin layout: Hiletgo TFT Screen (ILI9341)

TFT Pin Arduino Pin Notes

VCC 3.3V Power supply for the TFT screen.

GND GND Ground connection.

CS Digital 6 Chip Select pin.

RST Digital 9 Reset pin.

DC Digital 10 Data/Command pin.

SDI (MOSI) Digital 11 SPI Master Out Slave In (MOSI).

SCK Digital 13 SPI Clock.

LED 3.3V Backlight power.


pin layout for:LCD 1602

VSS GND Ground connection.

VDD 5V Power supply for the LCD.

VO Center pin of potentiometer Contrast adjustment. Use a potentiometer (10kΩ).

RS Digital 8 Register Select pin.

RW GND Read/Write pin. Set to GND for write-only mode.

E Digital 7 Enable pin.

D4 Digital 5 Data pin D4.

D5 Digital 4 Data pin D5.

D6 Digital 3 Data pin D6.

D7 Digital 2 Data pin D7.

A (LED+) 5V Backlight positive

K (LED-) GND Backlight ground


Software

Overview

The project implements a slot machine game using an Arduino Uno microcontroller, interfaced with two displays:

- Hiletgo TFT Display (ILI9341): Used to render the slot machine's grid and animations.

- 1602A LCD Display: Used for displaying credits and bet information dynamically.

The game supports user interaction through buttons to play, adjust bets, and add credits. It simulates the slot machine's behaviour by employing a combination of probability-based symbol weights, payout logic, and a random number generation mechanism.


Key Features

Rendering of Symbols and Grid:

- The slot machine features a 3x5 grid of symbols rendered on the Hiletgo TFT display.

- Symbols are drawn as bitmaps using the Adafruit_GFX and Adafruit_ILI9341 libraries.

- Winning lines (horizontal and diagonal) are calculated dynamically, and the results are displayed on the TFT screen.

User Interaction:


- Buttons for playing the game, adjusting bets, and adding credits.

- Real-time updates of credits and bets displayed on the LCD.

Probability and Payout Logic:


- A weighted random selection system determines the appearance frequency of symbols.

- A payout multiplier table defines rewards based on the number of matching symbols on a winning line.

Libraries Used

- Adafruit_GFX:

Provides essential graphic rendering functionalities, such as drawing shapes, text, and bitmaps.

Used for rendering the grid and symbols on the TFT display.


- Adafruit_ILI9341:

Specialized library for interfacing with the Hiletgo TFT display using the ILI9341 driver.

Enables efficient SPI communication and fast bitmap rendering.


- LiquidCrystal:

Simplifies interaction with the 1602A LCD.

Used to display user data such as credits and bet amounts.

Game Logic

Symbol Rendering:

- Each symbol (e.g., Cherry, Apple, Seven) is represented by a bitmap image stored in memory.

- The drawSlotResult() function renders the random symbols on the grid based on the selected indices.


Weighted Probability System:

- Each symbol has an assigned weight defining its likelihood of appearing. Higher weights mean more frequent appearances.


Example:

Cherry and Banana have the highest weights, making them the most common.

Seven and Bar have the lowest weights, making them the rarest and most rewarding.

The pickWeightedSymbol() function uses a cumulative probability approach to select symbols based on their weights randomly.


Payout Logic

- Winning lines are predefined as rows and diagonals:

3 rows: Top, Middle, Bottom.

2 diagonals: Top-left to bottom-right and Bottom-left to top-right.


- For each winning line:

The number of matching symbols is calculated.

The payout multiplier is applied based on the symbol and the number of matches:

Payout=Multiplier[Symbol][MatchCount]×( Bet/10 )


Example:

A bet of 20 with 3 matching "Cherries" pays:

20×20/10=40.


- Play Button Logic

Deducts the current bet from credits.

Generates a random 3x5 grid of symbols.

Evaluate winning lines and calculate payouts.

Updates the display with results or "Game Over" if no credits remain.



Technical Details


- Initialization:

Pins for buttons and displays are defined.

Displays are initialized using their respective libraries.

A welcome screen is rendered on the TFT display during startup.


- Dynamic Credit and Bet Management:

The LCD continuously updates with real-time credit and bet values.

The "Add Credits" button instantly adds 200 credits for uninterrupted gameplay.


- Performance Optimizations:

SPI Communication: Ensures efficient rendering on the TFT display.

Delays: Minimal delays are introduced to balance gameplay speed and smoothness.


Project Flow


- Startup:

The welcome screen is displayed on the TFT.

Credits and bets are initialized on the LCD.


- Game Play:

Users adjust their bets using the "Bet Increase" and "Bet Decrease" buttons.

The "Play" button starts the game, deducting the bet and displaying random symbols.

Payouts are calculated for winning lines, and the LCD updates credits dynamically.


- Game Over:

A "Not Enough Credits" message is shown on the LCD if credits fall below the current bet.

Users can add credits using the dedicated button.


You can add extra steps for possible future improvements:

- Enhance Visual Effects:

Add animations for symbol transitions and winning lines.


- Sound Effects:

Include sounds for button presses, spinning reels, and wins.


- Extended Gameplay Features:

Introduce a bonus round or jackpot feature.

Add support for saving and resuming game states.



You can find more information and the program files here.

Soldering the Electronics Together

There are three main components: the main screen, the bet screen, and buttons.

1. Main screen:

The layout is the following: Screen --> male-female cables --> current divider--> board pins --> digital Arduino pins

2. Bet screen:

The layout is the following: Screen --> male-female cables --> board pins --> digital Arduino pins

3. Buttons:

The layout is the following: Buttons --> board--> male-female cables --> analogue Arduino pins

Both screens had to be attached to an auxiliary board and soldered, for easier pin/cable management, while the buttons were directly connected to the analog pins.


3D Print the Box / Frame

WhatsApp-kép, 2025-01-21, 21.36.06_ef852171.jpg

3D-Printed Enclosure Design

The enclosure, designed using 3ds Max software, consists of three components:


Main Box:

Base: 7.4 cm x 9 cm.

Upper Section: 9 cm x 9 cm with a height of 15 cm.

Purpose: Houses internal electronics.


Back Lid:

Dimensions: 8.4 cm x 15 cm.

Function: Slides into the rear for secure closure and access.


Legs:

Attachment: Glued to the box base.

Purpose: Provides stability and elevation.


Assembly:

Glue the legs to the box base.

Install internal components.

Slide the back lid to close.


You can find more information, and the files for 3D printing here.

Summary

The Sloth Machine project is an interactive slot machine powered by an Arduino Uno. It uses a Hiletgo TFT screen for animations and a 1602A LCD for credit and bet updates, with user interactions through buttons. The software features weighted random symbols and payout calculations, ensuring a dynamic gameplay experience. Key components are housed in a 3D-printed enclosure, and the system uses libraries like Adafruit_GFX for smooth graphics. This project showcases the combination of hardware and software to create an engaging device with potential for future improvements.