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

◆ highLowFloating()

bool fl::ButtonLowLevel::highLowFloating ( )

Definition at line 22 of file button.cpp.

22 {
23 // FastLED doesn't have reliable support for pullups/pulldowns.
24 // So we instead use a strategy where the pin is set to high, then
25 // checked if it's high, then set to low, and then checked if it's low
26 // if this is the case, then the pin is floating and thefore the button is
27 // not being pressed.
28 mPin.setPinMode(DigitalPin::kOutput);
29 mPin.write(true); // set pin to high
30 mPin.setPinMode(DigitalPin::kInput);
31 const bool was_high = mPin.high(); // check if pin is high
32 mPin.setPinMode(DigitalPin::kOutput);
33 mPin.write(false); // set pin to low
34 mPin.setPinMode(DigitalPin::kInput);
35 const bool was_low = !mPin.high(); // check if pin is low
36 const bool floating =
37 was_high && was_low; // if both are true, then the pin is floating
38 const bool pressed =
39 !floating; // if the pin is floating, then the button is not pressed
40 return pressed;
41}
fl::DigitalPin mPin
Definition button.h:43

References fl::DigitalPin::kInput, fl::DigitalPin::kOutput, and mPin.

Referenced by isPressed().

+ Here is the caller graph for this function: