The snippet library.
Small, practical examples. Search by task or narrow things down below.
Apply a linear sensor calibration
Arduino / C: Convert a raw reading using an offset and scale measured for the sensor.
Arduino / C✓ Tested
Convert a supplied ADC count to volts
Arduino / C: Scale a ten-bit ADC count using an explicit reference voltage.
Arduino / C✓ Tested
Convert Celsius to Fahrenheit
Arduino / C: Use floating-point constants to avoid integer division.
Arduino / C✓ Tested
Ignore small movements around a center value
Arduino / C: Values inside the deadband become zero while others keep their direction.
Arduino / C✓ Tested
Interpolate between two calibration points
Arduino / C: Compute a fractional position before scaling to the output interval.
Arduino / C✓ Tested
Maintain a rolling sum in a circular window
Arduino / C: Subtract the overwritten sample before adding the next one.
Arduino / C✓ Tested
Prevent output chatter with separate thresholds
Arduino / C: Use different on and off thresholds to retain state between them.
Arduino / C✓ Tested
Reject one outlier with a median-of-three filter
Arduino / C: Sorting three values leaves the median in the middle.
Arduino / C✓ Tested
Represent a decimal quantity with a scaled integer
Arduino / C: Integer hundredths avoid floating-point storage for fixed-precision values.
Arduino / C✓ Tested
Smooth a sequence with an exponential filter
Arduino / C: Blend each sample with the previous filtered value.
Arduino / C✓ Tested