adafruit / Adafruit_TCS34725

Arduino library driver for Adafruit's TCS34725 RGB Color Sensor Breakout
http://www.adafruit.com/products/1334
Other
151 stars 151 forks source link

Use computed delay instead of case-switch #38

Closed itsayellow closed 4 years ago

itsayellow commented 4 years ago

This replaces the case-switch statement for creating an integration time delay with a computed delay using efficient integer math. It allows any arbitrary value of ATIME (and hence _tcs34725IntegrationTime) to be used.

Literal ints use at least 16-bits on Arduino so the computation will not suffer from overflow errors. As a side benefit, it uses 126 less bytes of program storage space.

The old version would add no delay if integration time was set to any other value than the enumerated ones. This would result in the same measurement being read multiple times, an error.

This version gives much more flexibility for setting integration times and still be functional.

itsayellow commented 4 years ago

Closing because the changes are now part of #37.