# ๐Ÿ“˜ **Arduino Jump Dash โ€” Full Project README** ## ๐ŸŽฎ Overview This project connects a **browser-based Geometry Dashโ€“style game** with an **Arduino board**. The player controls the jumping character using: * A **physical button** connected to the Arduino * Or the **space bar** on the keyboard * (Optional) Touch input on mobile The Arduino communicates with a **Node.js backend**, which relays player actions to the **browser game** using WebSockets. The game sends back **score** and **death statistics**, which the backend forwards to the Arduino. The Arduino displays these values on a **7-segment display**. The whole system is fully bidirectional: ``` Arduino (Button) โ†’ Node Backend โ†’ Game Browser (Jump Input) Game Browser (Score/Deaths) โ†’ Node Backend โ†’ Arduino (Seven Segment Display) ``` --- # ๐Ÿงฑ **Project Architecture** ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” WebSocket โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Browser Game (JS) โ”‚ <--------------> โ”‚ Node.js Backend โ”‚ โ”‚ - Canvas runner โ”‚ โ”‚ - Express static serverโ”‚ โ”‚ - Jump logic โ”‚ โ”‚ - WebSocket server โ”‚ โ”‚ - Obstacle system โ”‚ โ”‚ - SerialPort interface โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ Serial USB โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Arduino โ”‚ โ”‚ - Button input โ”‚ โ”‚ - Seven segment display output โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` --- # ๐Ÿ› ๏ธ **Technologies Used** ### **Frontend** * HTML5 Canvas * CSS responsive layout (mobile-friendly) * Vanilla JavaScript game engine * WebSocket client * Keyboard & touch controls ### **Backend** * Node.js + Express * WebSocket (ws) * SerialPort (for Arduino communication) ### **Hardware** * Arduino * Push button (for jump input) * Seven-segment display (via SevSeg library) --- # ๐Ÿ”Œ **Setup Instructions** ## 1๏ธโƒฃ Install Dependencies ### **Node backend** ```bash npm install express ws serialport ``` ### **Arduino** Install the **SevSeg** library: **Arduino IDE โ†’ Sketch โ†’ Include Library โ†’ Manage Libraries โ†’ Search โ€œSevSegโ€** --- # ๐Ÿ“ **Project Structure** ``` /project โ”‚ โ”œโ”€โ”€ public/ โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ”œโ”€โ”€ style.css โ”‚ โ””โ”€โ”€ game.js โ”‚ โ”œโ”€โ”€ server.js # Node.js backend โ”œโ”€โ”€ arduino.js (optional - for simulation) โ””โ”€โ”€ README.md ``` --- # ๐Ÿ–ฅ๏ธ **Frontend Game Features** * Geometry Dashโ€“style gameplay * Ground + obstacles moving rightโ†’left * Player jumps with: * Arduino button (via WebSocket) * Spacebar on keyboard * Touch on mobile * Scoring system: * +1 for every obstacle cleared * Death detection and game over UI * Restart button * Fully responsive + centered canvas --- # ๐ŸŒ **WebSocket Protocol** ### **Browser โ†’ Backend (Game Events)** #### Score update: ```json { "type": "score", "score": 12 } ``` #### Death event: ```json { "type": "death", "deaths": 3 } ``` ### **Backend โ†’ Browser (Jump Input)** Sent when Arduino button is pressed: ```json { "action": "jump" } ``` --- # ๐Ÿ” **Backend Responsibilities** * Serve the frontend game files * Maintain WebSocket connections * Receive serial events from Arduino (`"JUMP"`) * Forward `"jump"` action to browser clients * Receive score/death stats from browser * Format and send them to Arduino via serial: * `S` for score * `D` for deaths Example: ``` S15\n โ†’ show score 15 on seven segment D3\n โ†’ show deaths 3 on seven segment ``` --- # ๐Ÿ”ง **Arduino Responsibilities** * Detect button press โ†’ send `"JUMP\n"` via Serial * Receive messages from backend: * `S##` โ†’ update score display * `D##` โ†’ update death count * Use SevSeg to draw numbers on seven-segment display Pseudo-protocol: ``` PC to Arduino: S42 โ†’ set score to 42 D7 โ†’ set death count to 7 Arduino to PC: JUMP โ†’ player pressed the button ``` --- # ๐Ÿงช **Testing Without Arduino (Virtual Serial Ports)** You can create paired virtual serial ports (e.g., using `socat` on Linux/macOS or com0com on Windows). Then run the simulator: ```bash node arduino.js ``` Press Enter to simulate a button press โ†’ game character jumps. --- # ๐Ÿ“ฑ **Responsive UI Features** * Canvas centered via flexbox * Scales with `aspect-ratio` * Score & Game Over UI positioned relative to game container * Mobile-friendly touch support