MCPcopy Create free account
hub / github.com/FastLED/FastLED / normalized

Method normalized

src/fl/sensors/potentiometer.cpp.hpp:46–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46float Potentiometer::normalized() const {
47 // Handle invalid range
48 if (mMaxValue <= mMinValue) {
49 return 0.0f;
50 }
51
52 // Clamp current value to calibrated range
53 u16 clamped_value;
54 if (mCurrentValue < mMinValue) {
55 clamped_value = mMinValue;
56 } else if (mCurrentValue > mMaxValue) {
57 clamped_value = mMaxValue;
58 } else {
59 clamped_value = mCurrentValue;
60 }
61
62 // Map calibrated range to [0.0, 1.0]
63 u16 range = mMaxValue - mMinValue;
64 u16 offset = clamped_value - mMinValue;
65 return static_cast<float>(offset) / static_cast<float>(range);
66}
67
68u16 Potentiometer::fractional16() const {
69 // Handle invalid range

Callers 2

onEndFrameMethod · 0.80
FL_TEST_FILEFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected