CodeRigor

GUIDED LESSON / 6 OF 6

Finish a reproducible C++ hardware project

Keep the interface, limits and next scheduling question clear.

What moves through this step
  1. 01Host tests
  2. 02Sketch build
  3. 03Bench observations
  4. 04Next experiment

Package something another learner can reproduce

Keep the sketch, its policy header, desktop tests and a short README together. List the hardware, exact pin map, compiler/board package version and one working upload procedure. State that the measurement uses a nominal sound speed and a bounded blocking echo wait.

The policy functions return values and do not own pins or serial ports. The sketch owns those device interactions. That boundary makes desktop tests useful without pretending the computer has measured an ultrasonic pulse.

Choose a useful extension

A different display adapter could show the zone on the UNO R4 WiFi's onboard matrix. Keep zone_for unchanged and consult the board's matrix API for the display work.

A more advanced extension replaces pulseIn with an interrupt or timer-capture implementation. First define which context owns timestamps, how incomplete measurements expire and how shared state crosses the interrupt boundary. Follow the free microcontroller and RTOS lessons before introducing concurrency.

Completion check

Explain why echo time is divided by two, why the zero case is handled first, which functions are safe to include in more than one translation unit and how unsigned subtraction handles the ordinary millis() wrap. Show your host-test result, successful sketch compilation and actual desk measurements as three separate pieces of evidence.