Project Overview
"Switch-Link" is a foundational exploration into Input-Output (IO) Forensics and Scalable Embedded Architecture. Handling multiple physical switches in a single firmware loop is often complicated by electrical noise and varying mechanical topologies. Switch-Link provides a unified struct-based framework that polls mixed switch types (Buttons vs. Toggles) concurrently, leveraging Non-Blocking Debounce Logic and State-Change Detection to ensure high reliability in complex HMI environments.
Technical Deep-Dive
- Mixed Topology Polling Forensics:
- Unified Signal Conditioning: The framework supports two primary wiring schemes:
Circuit_C1(External Pull-Down) andCircuit_C2(Internal Pull-Up). By abstracting the circuit type into a firmware pre-set, the system normalizes the logic: an "Active" state is always resolved as a booleanTRUEregardless of the electrical polarity (High vs. Low). - The Polling vs. Interrupt Trade-off: While interrupts are efficient for sparse events, polling is superior for high-density matrices where multiple switches must be analyzed sequentially within a single CPU cycle.
- Unified Signal Conditioning: The framework supports two primary wiring schemes:
- State-Change Edge Detection Logic:
- Momentary vs. Persistent Status: The system distinguishes between the "Momentary" nature of buttons (which require a rising-edge trigger) and the "Persistent" status of toggle switches. For toggles, the current state $(\text{ON} \leftrightarrow \text{OFF})$ persists in memory after the read, allowing the logic to be checked globally across the main loop.
- The Transition Buffer: The firmware monitors the
lastButtonStatevector. An action is only triggered when a delta $(\Delta)$ is detected between the current and previous poll, preventing redundant command execution during held states.
- Non-Blocking Debounce Diagnostics:
- Contact Bounce Suppression: Mechanical switches suffer from "Bounce"—a millisecond-scale electrical oscillation during closure. Switch-Link utilizes a
millis()-based lockout timer (e.g., 50ms), ensuring the system only accepts a stable signal transition, preventing "Double-Trigger" artifacts without the CPU stalling inherent indelay()logic.
- Contact Bounce Suppression: Mechanical switches suffer from "Bounce"—a millisecond-scale electrical oscillation during closure. Switch-Link utilizes a
Engineering & Implementation
- Architecture Scalability:
- Resource Footprint: Each additional switch configured in the
switch_controlstruct adds approximately 13 bytes of SRAM and 13 bytes of Flash. This high-efficiency forensics allows an Arduino Uno to manage dozens of switches, provided pin-count limitations are resolved via shift registers or multiplexers.
- Resource Footprint: Each additional switch configured in the
- Configuration Logistics:
- Step 1: Macro Matrix. Define pins using descriptive macros (e.g.,
BUTTON_SHUTDOWN,TOGGLE_MAINS). - Step 2: Struct Declaration. Map the physical pin to its logical behavior (Momentary or Toggle).
- Step 3: Switch-Case Execution. Use the
switchedstatus returned by the polling function to trigger specific mechatronic tasks in the main loop.
- Step 1: Macro Matrix. Define pins using descriptive macros (e.g.,
Conclusion
Switch-Link demonstrates the power of Unified Code Design. By mastering Mixed Topology Forensics and State-Change Detection, developers can build robust, industrial-grade control panels that handle complex human inputs with deterministic reliability and minimal hardware overhead.