|
| 1 | +# Slot Machine |
| 2 | +A mini slot machine that accepts real coins, spins three physical reels, and dispenses a payout on win. |
| 3 | + |
| 4 | +:::info |
| 5 | + |
| 6 | +**Author**: Teodor Adrian Miron \ |
| 7 | +**GitHub Project Link**: [https://github.com/UPB-PMRust-Students/acs-project-2026-teodoradriann](https://github.com/UPB-PMRust-Students/acs-project-2026-teodoradriann) |
| 8 | + |
| 9 | +::: |
| 10 | + |
| 11 | +<!-- do not delete the \ after your name --> |
| 12 | + |
| 13 | +## Description |
| 14 | + |
| 15 | +My project consists in building a mini Slot Machine where you can insert coins and bet X amount of credited money. The system uses a load cell to count coins and three stepper motors to physically roll the reels. The game is initiated via a dedicated Spin button, and if the player wins, the amount is dispensed physically using a servo-driven payout mechanism. |
| 16 | + |
| 17 | +## Motivation |
| 18 | + |
| 19 | +I wanted to do something fun and help students control their gambling addiction with tiny amounts of money. |
| 20 | + |
| 21 | +## Architecture |
| 22 | + |
| 23 | +The software architecture is based on a Finite State Machine (FSM) managing the game flow, implemented in Rust using the Embassy framework for async multitasking. |
| 24 | + |
| 25 | + - The main components (architecture components, not hardware components): |
| 26 | + - **Core Logic / State Machine**: manages game states (`IDLE`, `WAITING_FOR_BET`, `SPINNING`, `PAYOUT`) and coordinates all modules. |
| 27 | + - **Input / Sensor Manager**: handles debouncing for the Spin and Bet buttons and interprets weight signals from the load cell. |
| 28 | + - **Random Number Generator (RNG)**: responsible for the fair generation of the spin outcome. |
| 29 | + - **Motor / Actuator Controller**: translates the RNG result into steps for the 3 stepper motors and PWM signals for the payout servo. |
| 30 | + - **Display / UI Controller**: manages the ST7735 LCD, displaying credit balance and bet amount. |
| 31 | + - **Payout Manager**: commands the servo motor to eject the coins. |
| 32 | + - How they connect with each other: |
| 33 | + - The Input Manager detects a coin (weight increase) or a button press and sends an event to the Core Logic. |
| 34 | + - Core Logic updates the credit and instructs the Display Controller to refresh. |
| 35 | + - When the Spin button is pressed, Core Logic switches to the `SPINNING` state and requests a value from the RNG. |
| 36 | + - The Motor Controller starts the 3 stepper motors and stops them sequentially based on the RNG result. |
| 37 | + - If a win is detected, the Payout Manager activates the servo to slide coins out of the storage tube. |
| 38 | + |
| 39 | +## Log |
| 40 | + |
| 41 | +<!-- write your progress here every week --> |
| 42 | + |
| 43 | +### Week 5 - 11 May |
| 44 | + |
| 45 | +### Week 12 - 18 May |
| 46 | + |
| 47 | +### Week 19 - 25 May |
| 48 | + |
| 49 | +## Hardware |
| 50 | + |
| 51 | +The build uses a microcontroller board driving a small TFT display, an HX711 + load cell pair for detecting inserted coins by weight, three 28BYJ-48 stepper motors with ULN2003 drivers for the physical reels, a continuous-rotation servo for the payout mechanism, arcade buttons for player input, and a 5 V stabilized power supply to handle motor peak currents. |
| 52 | + |
| 53 | +### Schematics |
| 54 | + |
| 55 | +Place your KiCAD or similar schematics here in SVG format. |
| 56 | + |
| 57 | +### Bill of Materials |
| 58 | + |
| 59 | +<!-- Fill out this table with all the hardware components that you might need. |
| 60 | +
|
| 61 | +The format is |
| 62 | +``` |
| 63 | +| [Device](link://to/device) | This is used ... | [price](link://to/store) | |
| 64 | +
|
| 65 | +``` |
| 66 | +
|
| 67 | +--> |
| 68 | + |
| 69 | +| Device | Usage | Price | |
| 70 | +|--------|-------|-------| |
| 71 | +| [DS04-NFC Continous Rotation Servo](https://www.optimusdigital.ro/en/servomotors/1161-ds04-nfc-continous-rotation-servo.html) | Drives the coin payout mechanism | [39 RON](https://www.optimusdigital.ro/en/servomotors/1161-ds04-nfc-continous-rotation-servo.html) | |
| 72 | +| [5 V 5000 mA Stabilized Power Supply](https://www.optimusdigital.ro/en/wall-socket-power-supplies/2890-5-v-5000-ma-stabilized-power-supply.html) | Powers the motors and the rest of the system | [30 RON](https://www.optimusdigital.ro/en/wall-socket-power-supplies/2890-5-v-5000-ma-stabilized-power-supply.html) | |
| 73 | +| [1.44" SPI LCD Module with ST7735 Controller (128x128 px)](https://www.optimusdigital.ro/en/lcds/3552-modul-lcd-de-144-cu-spi-i-controller-st7735-128x128-px.html) | Displays credit balance, bet amount and reel animation | [30 RON](https://www.optimusdigital.ro/en/lcds/3552-modul-lcd-de-144-cu-spi-i-controller-st7735-128x128-px.html) | |
| 74 | +| [ULN2003 Stepper Driver + 5V Stepper Motor](https://www.optimusdigital.ro/en/stepper-motors/101-stepper-motor-with-uln2003-driver.html) (x3) | Physically rolls the three reels | [17 RON](https://www.optimusdigital.ro/en/stepper-motors/101-stepper-motor-with-uln2003-driver.html) | |
| 75 | +| [Arcade Button 24 mm - Green](https://www.optimusdigital.ro/en/buttons-and-switches/1851-buton-arcade-iluminat-24mm-verde.html) | Spin / bet input from the player | [10 RON](https://www.optimusdigital.ro/en/buttons-and-switches/1851-buton-arcade-iluminat-24mm-verde.html) | |
| 76 | +| [HX711 GroundStudio Load Cell Amplifier](https://ardushop.ro/ro/groundstudio/2207-modul-citire-senzor-greutate-hx711-groundstudio-6427854000040.html) | Reads digital weight values from the load cell | [11 RON](https://ardushop.ro/ro/groundstudio/2207-modul-citire-senzor-greutate-hx711-groundstudio-6427854000040.html) | |
| 77 | +| [Load Cell (max. 1 Kg)](https://ardushop.ro/ro/electronica/2418-1349-senzor-greutate.html#/246-greutate_maxima-1_kg) | Detects inserted coins by weight | [10 RON](https://ardushop.ro/ro/electronica/2418-1349-senzor-greutate.html#/246-greutate_maxima-1_kg) | |
| 78 | + |
| 79 | +## Software |
| 80 | + |
| 81 | +| Library | Description | Usage | |
| 82 | +|---------|-------------|-------| |
| 83 | +| [embassy-stm32](https://github.com/embassy-rs/embassy) | STM32 hardware driver | Controlling pins, timers (PWM for the servo) and SPI for the LCD | |
| 84 | +| [embassy-time](https://github.com/embassy-rs/embassy) | Time and delay management | Non-blocking delays for stepper motor steps and animations | |
| 85 | +| [embassy-executor](https://github.com/embassy-rs/embassy) | Async task scheduler | Running multiple tasks (motors, UI, sensors) concurrently | |
| 86 | +| [embassy-sync](https://github.com/embassy-rs/embassy) | Async sync primitives | Inter-task communication (e.g. sending coin weight data to the UI) | |
| 87 | +| [cortex-m](https://github.com/rust-embedded/cortex-m) | Core processor access | Managing interrupts and CPU-specific instructions | |
| 88 | +| [cortex-m-rt](https://github.com/rust-embedded/cortex-m) | Startup/Runtime for ARM | Initializing memory and the program entry point | |
| 89 | +| [defmt](https://github.com/knurling-rs/defmt) | Low-overhead logger | Fast logging for debugging sensor data and game states | |
| 90 | +| [defmt-rtt](https://github.com/knurling-rs/defmt) | RTT transport for logs | Viewing logs in real-time through the debugger | |
| 91 | +| [embedded-graphics](https://github.com/embedded-graphics/embedded-graphics) | 2D graphics library | Drawing fruit icons, text and shapes on the screen | |
| 92 | +| [st7735-lcd](https://crates.io/crates/st7735-lcd) | Display driver for ST7735 | Managing the command set for the 1.44" color TFT screen | |
| 93 | +| [hx711](https://crates.io/crates/hx711) | Load cell driver | Reading digital weight values from the load cell amplifier | |
| 94 | +| [panic-probe](https://github.com/knurling-rs/defmt) | Debug panic handler | Reporting and stopping the CPU safely if a runtime crash occurs | |
| 95 | + |
| 96 | +## Links |
| 97 | + |
| 98 | +<!-- Add a few links that inspired you and that you think you will use for your project --> |
| 99 | + |
| 100 | +1. [Slot machine reference video](https://youtu.be/ihVHIpEZ-Pw) |
0 commit comments