Skip to content

Pin Types & Sampling

ConstantDirectionAvailable built-in tools
MCP_DIGITAL_OUTPUTOutputgpio_write, gpio_read
MCP_DIGITAL_INPUTInputgpio_read
MCP_PWM_OUTPUTOutputpwm_write
MCP_ADC_INPUTInputadc_read

When registering input pins, you can add sampling options to enable automatic periodic reading and statistics:

HelperEnablesParameters
McpBuffered(bufferSize, intervalMs)summary + ring bufferbuffer size, sample interval
McpSummaryOnly(intervalMs)rolling statistics onlysample interval
McpThreshold(minValue, maxValue, intervalMs)summary + threshold eventsmin, max, sample interval
McpOutputSafe(approvalRequired)output safety metadataapproval flag
// Enable rolling statistics with 500ms sampling interval
mcp.add_pin(34, "light", MCP_ADC_INPUT, "Light sensor", McpSummaryOnly(500));
// Enable ring buffer with 20 samples, 500ms interval
mcp.add_pin(35, "temp", MCP_ADC_INPUT, "Temp sensor", McpBuffered(20, 500));
// Enable threshold events
mcp.add_pin(36, "pressure", MCP_ADC_INPUT, "Pressure sensor", McpThreshold(0, 100, 1000));

When a pin is registered with McpBuffered, McpSummaryOnly, or McpThreshold, MCP-U samples it from loop() and exposes additional built-in tools.

Returns rolling statistics for a sampled pin.

Params: { "pin": "<name>" } or { "pin": <gpio> }

Response:

{
"pin": 34,
"name": "light",
"latest": 812,
"min": 120,
"max": 980,
"avg": 531.4,
"samples": 42
}

Returns recent samples from a ring buffer. limit is optional.

Params: { "pin": "<name>", "limit": 10 }

Response:

{
"pin": "light",
"count": 20,
"values": [402, 418, 421, 430]
}

If buffering is not available for a pin:

{
"pin": "light",
"buffer_available": false,
"reason": "Buffer disabled on this platform or pin. Use get_pin_summary instead."
}

Reports the current threshold state for pins registered with McpThreshold.

Params: { "pin": "<name>" }

Response:

{
"pin": "temperature",
"events": [
{ "type": "threshold_high", "value": 38.2, "threshold": 35 }
]
}