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

◆ highLowFloating()

bool fl::ButtonLowLevel::highLowFloating ( )

Definition at line 21 of file button.cpp.hpp.

21 {
22 // High-low floating detection: Set pin to high, check if high,
23 // set pin to low, check if low. If both conditions are true,
24 // the pin is floating and therefore the button is not pressed.
25 mPin.setPinMode(DigitalPin::kOutput);
26 mPin.write(true); // set pin to high
27 mPin.setPinMode(DigitalPin::kInput);
28 const bool was_high = mPin.high(); // check if pin is high
29 mPin.setPinMode(DigitalPin::kOutput);
30 mPin.write(false); // set pin to low
31 mPin.setPinMode(DigitalPin::kInput);
32 const bool was_low = !mPin.high(); // check if pin is low
33 const bool floating =
34 was_high && was_low; // if both are true, then the pin is floating
35 const bool pressed =
36 !floating; // if the pin is floating, then the button is not pressed
37 return pressed;
38}
fl::DigitalPin mPin
Definition button.h:46

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

Referenced by isPressed().

+ Here is the caller graph for this function: