# cxrphly/line-bot architecture

> Architecture diagram of the GitHub repository cxrphly/line-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cxrphly/line-bot
- Repository: https://github.com/cxrphly/line-bot

## Overview

LineBot is an ESP32 line-following robot with PID-based autonomous driving, Bluetooth manual control, OLED menus and calibration/configuration. The user connects a gamepad, selects a mode or adjusts settings, and the firmware reads sensors or controller inputs to drive the motors and update the display. Calibration and PID settings persist in ESP32 preferences. The README also documents 3D-printable and laser-cut chassis designs. The main sketch was not sampled, so its setup/loop wiring is not shown; runtime links below follow only the sampled calls and documented capabilities.

Main entry points: [`gamepad.cpp`](https://github.com/cxrphly/line-bot/blob/main/gamepad.cpp) (Gamepad handling), [`LineFollower.cpp`](https://github.com/cxrphly/line-bot/blob/main/LineFollower.cpp) (Line-follow control), [`motors.cpp`](https://github.com/cxrphly/line-bot/blob/main/motors.cpp) (Motor control), [`oled_ui.cpp`](https://github.com/cxrphly/line-bot/blob/main/oled_ui.cpp) (OLED menus)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Control and display"]
  node_gamepad_logic["Gamepad handling<br/>[gamepad.cpp]"]
  node_oled_ui["OLED menus<br/>[oled_ui.cpp]"]
  node_config["Pin and runtime config<br/>[config.h]"]
end

subgraph group_autonomy["Line following"]
  node_line_control["Line-follow control<br/>[LineFollower.cpp]"]
  node_qtr["QTR sensor array"]
  node_calibration["Sensor calibration<br/>[LineFollower.cpp]"]
  node_preferences[("ESP32 preferences")]
end

subgraph group_hardware["Robot hardware"]
  node_motor_control["Motor control<br/>[motors.cpp]"]
  node_motor_driver["TB6612 motor driver"]
  node_oled["OLED display"]
end

subgraph group_fabrication["Chassis designs"]
  node_design_3d["3D models and parts"]
  node_design_laser["Laser-cut chassis"]
end

node_operator(("Robot operator"))
node_gamepad(("Bluetooth gamepad"))

node_operator -->|"presses controls"| node_gamepad
node_gamepad -.->|"sends inputs"| node_gamepad_logic
node_gamepad_logic -->|"updates menus"| node_oled_ui
node_oled_ui -->|"draws screens"| node_oled
node_gamepad_logic -->|"manual drive"| node_motor_control
node_gamepad_logic -->|"starts calibration"| node_line_control
node_line_control -->|"reads sensors"| node_qtr
node_line_control -->|"sets speeds"| node_motor_control
node_calibration -->|"calibrates"| node_qtr
node_calibration -->|"turns robot"| node_motor_control
node_calibration -->|"reads/writes calibration"| node_preferences
node_line_control -->|"reads/writes PID settings"| node_preferences
node_gamepad_logic -->|"saves settings"| node_preferences
node_motor_control -->|"sets PWM and direction"| node_motor_driver
node_operator -->|"uses for fabrication"| node_design_3d
node_operator -->|"uses for fabrication"| node_design_laser

click node_gamepad_logic "https://github.com/cxrphly/line-bot/blob/main/gamepad.cpp"
click node_oled_ui "https://github.com/cxrphly/line-bot/blob/main/oled_ui.cpp"
click node_config "https://github.com/cxrphly/line-bot/blob/main/config.h"
click node_line_control "https://github.com/cxrphly/line-bot/blob/main/LineFollower.cpp"
click node_calibration "https://github.com/cxrphly/line-bot/blob/main/LineFollower.cpp"
click node_motor_control "https://github.com/cxrphly/line-bot/blob/main/motors.cpp"
click node_design_3d "https://github.com/cxrphly/line-bot/tree/main/design/3d"
click node_design_laser "https://github.com/cxrphly/line-bot/tree/main/design/laser-cut"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gamepad_logic,node_oled_ui,node_config toneBlue
class node_line_control,node_qtr,node_calibration,node_preferences toneAmber
class node_motor_control,node_motor_driver,node_oled toneMint
class node_design_3d,node_design_laser toneRose
class node_operator,node_gamepad toneIndigo
```

## Components

### Control and display

- [Gamepad handling](https://github.com/cxrphly/line-bot/blob/main/gamepad.cpp): `gamepad.cpp`
- [OLED menus](https://github.com/cxrphly/line-bot/blob/main/oled_ui.cpp): `oled_ui.cpp`
- [Pin and runtime config](https://github.com/cxrphly/line-bot/blob/main/config.h): `config.h`

### Line following

- [Line-follow control](https://github.com/cxrphly/line-bot/blob/main/LineFollower.cpp): `LineFollower.cpp`
- **QTR sensor array**
- [Sensor calibration](https://github.com/cxrphly/line-bot/blob/main/LineFollower.cpp): `LineFollower.cpp`
- **ESP32 preferences**

### Robot hardware

- [Motor control](https://github.com/cxrphly/line-bot/blob/main/motors.cpp): `motors.cpp`
- **TB6612 motor driver**
- **OLED display**

### Chassis designs

- [3D models and parts](https://github.com/cxrphly/line-bot/tree/main/design/3d): `design/3d`
- [Laser-cut chassis](https://github.com/cxrphly/line-bot/tree/main/design/laser-cut): `design/laser-cut`

### Other components

- **Robot operator**
- **Bluetooth gamepad**

## Connections

- Robot operator → Bluetooth gamepad: presses controls
- Bluetooth gamepad → Gamepad handling: sends inputs
- Gamepad handling → OLED menus: updates menus
- OLED menus → OLED display: draws screens
- Gamepad handling → Motor control: manual drive
- Gamepad handling → Line-follow control: starts calibration
- Line-follow control → QTR sensor array: reads sensors
- Line-follow control → Motor control: sets speeds
- Sensor calibration → QTR sensor array: calibrates
- Sensor calibration → Motor control: turns robot
- Sensor calibration → ESP32 preferences: reads/writes calibration
- Line-follow control → ESP32 preferences: reads/writes PID settings
- Gamepad handling → ESP32 preferences: saves settings
- Motor control → TB6612 motor driver: sets PWM and direction
- Robot operator → 3D models and parts: uses for fabrication
- Robot operator → Laser-cut chassis: uses for fabrication
