Back to engineering archive

Record 025 / Connected systems

ESP32-C3 lap timer and servo gate

Provide a local browser interface to release a toy car and measure its lap time.

Prototype development
ESP32-C3Wi-Fi access pointBrowser interfaceServo controlSensor inputs

Firmware flow

Report one finish result for each track

The same visible branch appears in two finish handlers. This diagram follows the screenshot-transcribed code; it is not a hardware test.

A positive start timestamp and a clear finish flag allow the handler to format a track-tagged elapsed time and call WebSocket send. The flag is then set; repeated calls skip this branch while it remains set.

The send result is not checked. These lines do not establish successful delivery, timing accuracy or safe interrupt-context operation.

Read the visible handlers

Transcribed from setup-document screenshots of main.cpp. Only the fully visible handlers are reproduced; the original source files were not available. Indentation is normalized.

Track 1: finishISR

void IRAM_ATTR finishISR() {
  if (!finished1 && startTime1 > 0) {
    float t = (millis() - startTime1) / 1000.0;
    char buf[16];
    int n = snprintf(buf, sizeof(buf), "F1,%.2f", t);
    webSocket.send(buf);
    finished1 = true;
  }
}

Track 2: finish2ISR

void IRAM_ATTR finish2ISR() {
  if (!finished2 && startTime2 > 0) {
    float t = (millis() - startTime2) / 1000.0;
    char buf[16];
    int n = snprintf(buf, sizeof(buf), "F2,%.2f", t);
    webSocket.send(buf);
    finished2 = true;
  }
}
CheckFinish flag clear and start timestamp positive?The visible condition is !finished && startTime > 0.
ActionCalculate seconds and format the result(millis() - startTime) / 1000.0; format F1 or F2 and two decimal places into a 16-byte buffer.
ActionCall webSocket.send(buf)The return value is not checked in these lines.
ActionSet the finished flag to trueThis assignment follows the send call without a success check.
ResultExit the handlerNo reset or rearming logic is shown in the selected scope.

Technical notes and evidence limits

Four board roles

The setup document separates the system across four ESP32-C3 boards: a race host, a first-track sensor, a second-track starter and a second-track sensor. These are documented board roles, not evidence of a completed end-to-end test.

Servo and sensor signals

The wiring instructions assign GPIO 10 to the servo signals and GPIO 9 to the sensor signals. The selected source screenshots also declare each sensor input on GPIO 9; they do not establish the sensor technology or electrical validation.

State visible around the handlers

Each finished flag is declared false above its handler. Each start timestamp is declared without an explicit initializer in that visible declaration. Start-event assignment, later reset and rearming are outside the selected code, as are the WebSocket connection setup and interrupt attachment.

Runtime and evidence limits

The IRAM_ATTR-labelled handlers format text and call network I/O. If attached to a hardware interrupt, those operations require an interrupt-safety review. The formatting result is stored but not checked, the send result is unchecked, and the finished flag is set after the call regardless of its returned result. The screenshots do not establish debounce, delivery acknowledgement, race-start coordination, measured timing accuracy or physical test results.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project