When Software Events Start Driving the Physical World

    This article walks through how an abstract software event can be turned into a physical action, using a USB-powered desktop figurine that jumps whenever an AI coding assistant waits for input. It breaks the project into five layers—event source, event adapter, transport, execution, and mechanics/power—and explains hook scripts, serial/Wi-Fi/Bluetooth transport choices, a non-blocking microcontroller state machine, coil driving, mechanical guidance, and power constraints. It also covers a mini fax machine case study and the security lessons of exposing any input channel to the public internet, ending with a practical implementation checklist.

    1. Starting With a Small Figurine That Jumps

    A palm-sized figurine sits on a desk, motionless most of the time. When you interact with an AI coding assistant in a terminal and it starts waiting for your input, the little figure suddenly begins jumping up and down. This toy-like effect is actually a common pattern in IoT and embedded projects: converting an abstract event from the software world into an observable action in the physical world.

    The main character in the original material is the official mascot of an AI coding assistant. A hardware enthusiast turned it into a physically moving model, powered and connected over USB. The enclosure went through three iterations: first a common FDM plastic print, then brass, and finally CNC-machined aluminum with an anodized surface that feels close to a high-end laptop shell. The internal mechanism is simple: a microcontroller plus an electromagnet coil. The coil drives the model up and down, and a thin stainless steel rod passes through a sintered bronze sleeve as a guide to suppress lateral wobble.

    What is worth learning is not the appearance, but the way this chain is layered: event source → event adapter → transport → execution → mechanics and power. Any project that maps software state to physical action can be broken down and implemented across these five layers.

    2. Event Hooks: Exposing the Software’s Key Moments

    Modern AI coding tools generally provide a “hook” mechanism that lets developers run custom scripts at specific lifecycle points, such as task start, human confirmation required, task completion, and before or after tool calls. Its value is that it does not intrude on the main flow; side scripts handle auditing, notifications, formatting, test triggering, and other add-on logic.

    A typical neutral configuration example (field names vary slightly across tools; this only shows the structure):

    1. {
    2. "hooks": {
    3. "Notification": [
    4. { "matcher": "*", "hooks": [{ "type": "command", "command": "~/bin/notify.sh" }] }
    5. ],
    6. "Stop": [
    7. { "matcher": "*", "hooks": [{ "type": "command", "command": "~/bin/notify.sh done" }] }
    8. ]
    9. }
    10. }

    Three engineering points matter. First, hook scripts must return quickly; any blocking will slow down the main flow. Second, the hook runtime environment may differ from your login shell, so always use absolute paths and set the interpreter explicitly. Third, a hook failure should not affect the main task; the script should swallow exceptions internally and exit with a zero status code.

    3. From Event to Signal: Choosing the Transport Layer

    After the adapter receives an event, it needs to deliver “what happened” to the execution end. Three common options:

    • Wired serial: lowest latency and simplest to implement, suitable for fixed desktop devices; the downside is limited cabling.
    • Wireless LAN: reports via message publish/subscribe or lightweight requests, flexible to deploy, suitable for multiple devices; disconnection and duplicate messages must be handled.
    • Bluetooth Low Energy: friendly to power and size, suitable for battery-powered scenarios, but throughput and stability are weaker than the first two.

    Whichever you choose, follow the convention of “short message + idempotent event ID” so the execution end can safely deduplicate.

    4. Execution Layer: One Microcontroller Is Enough

    The core of the execution end is a non-blocking state machine, not stacked delay calls. Pseudocode:

    1. enum state { IDLE, BUZZ, COOLDOWN };
    2. void loop() {
    3. if (serial_available()) {
    4. evt = parse_event();
    5. if (!seen(evt.id)) { seen_add(evt.id); set_state(BUZZ); }
    6. }
    7. switch (state) {
    8. case BUZZ: pulse_coil(); if (--ticks == 0) set_state(COOLDOWN); break;
    9. case COOLDOWN: if (--ticks == 0) set_state(IDLE); break;
    10. default: sleep_ms(10); break;
    11. }
    12. }

    When driving the coil, always use a transistor or a dedicated driver chip. Never let coil current pass through the microcontroller’s I/O pins; leave enough margin for the flyback diode, current limiting, and heat dissipation. If using a wireless module, pay attention to instantaneous supply current and antenna clearance.

    5. Mechanics and Power: Details Determine the Feel

    • Guide structure: a thin rod with a bronze sleeve is a low-cost, high-return approach that significantly reduces lateral wobble and sticking; the clearance must be calculated against the tolerance chain.
    • Material choice: plastic parts suit rapid validation; metal parts (brass, aluminum) are better in texture and weight distribution; CNC machining plus anodizing yields a uniform surface.
    • Power source: drawing power over USB is the easiest, but you must respect its power supply limits and add current limiting and regulation when necessary.
    • Noise and feel: coil engagement produces sound and vibration; soft buffer pads can reduce the impact.

    6. Extended Practice: Printing Messages in Real Time

    The same author also built a mini fax machine around the same time: a low-cost thermal receipt printer, a second-hand phone, and a single-board computer, with the software again assisted by an AI coding assistant. It was assigned its own number, and friends could send a text message to print in real time. He then connected a website contact form to this machine, and it was quickly “reverse engineered” for its rate-limiting rules—someone split an entire animated movie script into pieces that each just barely bypassed the limit and sent them one by one, and the printer faithfully printed all of it.

    The lesson from this case is very general: any input channel exposed to the public internet must be assumed to be abused. At minimum it needs rate limiting and quotas, source validation and CAPTCHA, content length and type whitelists, deduplication and idempotency, exception circuit breaking and a manual switch, and complete logging and monitoring alerts. When cloud services are involved, you can combine general capabilities such as object storage for archiving, message queues for peak shaving, log services for retrieval, and monitoring alerts as a fallback, without binding to any proprietary interface.

    7. Implementation Checklist

    1. Define the event source and trigger conditions clearly; prefer the tool’s built-in hook mechanism and avoid modifying the main flow.
    2. Make the adapter non-blocking, degradable, and silent on failure.
    3. Once the transport is chosen, define the short message and idempotent ID conventions.
    4. Implement the execution layer with a state machine, and electrically isolate the driver circuit from the main controller.
    5. Prototype the mechanical structure in plastic first, then upgrade to metal parts and surface treatment.
    6. Add rate limiting, validation, circuit breaking, and alerts to any input exposed to the public internet.

    Connecting a “software event” to a “physical action”—the hard part has never been making it move, but making it keep moving stably, observably, and safely over the long term.