I generally avoid using floating point numbers with microcontrollers but I think this is one of those times floating point math has an advantage over integer math.

Even though I think floats are helpful in this project, integers are generally more precise. I'd avoid converting the pulse durations to distances until the last moment.

Instead of calculating two distances, subtract the two pulse durations and then calculate the distance based on this difference. This should reduce the rounding errors associated with converting back and forth between integers and floats.

Here's my speed calculation.

```
float objectSpeed = deltaPulseDuration * DELTA_T_TO_SPEED / measurementInterval;
```

Here's what I used for "DELTA_T_TO_SPEED".

```
const float IMPERICAL_CONVERSION = 56.0;
const float MICROSECONDS_PER_SECOND = 1000000.0;
const float DELTA_T_TO_SPEED = MICROSECONDS_PER_SECOND / IMPERICAL_CONVERSION;
```

"IMPERICAL_CONVERSION" is based on measurements made using my ultrasound. This value doesn't seem like it agrees with theory but it agrees with my 30cm, 40cm and 60cm observations. It sure bugs me that this value isn't what I get when I use the speed of sound in the calculation.

I'm still unsure when I should use a floating point number and when I should use integers but I decided to use a float for "measurementInterval" but "timeMark" and "previousTimeMark" are integers.

```
float measurementInterval = timeMark - previousTimeMark;
```

This is the sort of output I'm getting while the sensor is moving toward the computer monitor. I think the speed values seem reasonable.

```
duration = 3354 us, dist = 59.89 cm, deltaPDur = 168 us, deltaDist = 3.00 cm, interval = 108872.00 us, speed = 27.56 cm/s
duration = 2976 us, dist = 53.14 cm, deltaPDur = 378 us, deltaDist = 6.75 cm, interval = 108496.00 us, speed = 62.21 cm/s
duration = 2667 us, dist = 47.63 cm, deltaPDur = 309 us, deltaDist = 5.52 cm, interval = 108196.00 us, speed = 51.00 cm/s
duration = 2286 us, dist = 40.82 cm, deltaPDur = 381 us, deltaDist = 6.80 cm, interval = 107804.00 us, speed = 63.11 cm/s
duration = 2016 us, dist = 36.00 cm, deltaPDur = 270 us, deltaDist = 4.82 cm, interval = 107532.00 us, speed = 44.84 cm/s
duration = 1545 us, dist = 27.59 cm, deltaPDur = 471 us, deltaDist = 8.41 cm, interval = 107064.00 us, speed = 78.56 cm/s
duration = 1284 us, dist = 22.93 cm, deltaPDur = 261 us, deltaDist = 4.66 cm, interval = 106792.00 us, speed = 43.64 cm/s
```

"deltaPDur" is the change in the duration between the new and the previous pulse.

I'm certainly willing to post my full code, but I don't want to spoil the fun for anyone else who may be playing along.