Examples¶
The crate's examples/ are short stories, in reading order. Each is a small device or tool, the bug a plain u32 or f32 lets through there, how the type stops it, and what it costs at run time. CI builds them all.
Run one with the line at the top of its file, for example:
| # | Example | Features | The story |
|---|---|---|---|
| 1 | 01_timer |
time |
a debounce timeout set in ms and armed in µs |
| 2 | 02_thermostat |
thermal |
°C and °F setpoints; 1 °F of hysteresis is not −17.2 °C |
| 3 | 03_battery |
electrical,dimensionless,time |
bounded readings, a broken wire's 65535 refused, a counter that saturates |
| 4 | 04_motor_power |
electrical |
phase current through a shunt; mV/mΩ is A, mV·mA is µW |
| 5 | 05_light_sensor |
electrical,dimensionless |
kinds: a V/V gain is not a PWM duty, a TIA's V/A is not a resistor |
| 6 | 06_audio_limiter |
electrical,libm |
a limiter threshold in dBFS, worked out at compile time |
| 7 | 07_tone_generator |
dimensionless,angle |
a phase that wraps (Bam16) and a mix that saturates (Q15) |
| 8 | 08_data_logger |
counting,time |
channels from 1, ring slots from 0, packet numbers that wrap |
| 9 | 09_capture_buffer |
counting,time,information |
samples, bytes and cycles as dimensions; KiB is not kB |
| 10 | 10_adc_noise |
electrical,time |
an amplifier's nV/√Hz over a bandwidth |
| 11 | 11_us_customer |
customary |
setpoints in psi and gallons, US or imperial named |
| 12 | 12_wire |
shrink_wrap,time,electrical |
a reading sent to a PC tool, the same bytes as plain integers |
| 13 | 13_impedance_match |
electrical,angle,dimensionless,libm |
an antenna's Γ, VSWR and return loss; a dB limit as an integer compare |
| 14 | 14_iq_downconvert |
angle,dimensionless,electrical |
Q15 IQ samples mixed down by an NCO on a Cortex-M0 |
The lines that don't compile are in the files too, each with the compiler's real message.