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

Method highLowFloating

src/fl/sensors/button.cpp.hpp:21–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19ButtonLowLevel::~ButtonLowLevel() FL_NOEXCEPT {}
20
21bool ButtonLowLevel::highLowFloating() {
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}
39
40bool ButtonLowLevel::isPressed() {
41 switch (mStrategy) {

Callers

nothing calls this directly

Calls 3

setPinModeMethod · 0.45
writeMethod · 0.45
highMethod · 0.45

Tested by

no test coverage detected