FastLED 3.9.15
Loading...
Searching...
No Matches

◆ fractional16()

u16 Potentiometer::fractional16 ( ) const

Definition at line 68 of file potentiometer.cpp.hpp.

68 {
69 // Handle invalid range
70 if (mMaxValue <= mMinValue) {
71 return 0;
72 }
73
74 // Clamp current value to calibrated range
75 u16 clamped_value;
77 clamped_value = mMinValue;
78 } else if (mCurrentValue > mMaxValue) {
79 clamped_value = mMaxValue;
80 } else {
81 clamped_value = mCurrentValue;
82 }
83
84 // Map calibrated range to [0, 65535]
85 // Use 32-bit intermediate to avoid overflow
86 u32 range = mMaxValue - mMinValue;
87 u32 offset = clamped_value - mMinValue;
88 u32 scaled = (offset * 65535U) / range;
89 return static_cast<u16>(scaled);
90}
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)

References mCurrentValue, mMaxValue, mMinValue, and offset().

+ Here is the call graph for this function: