25 #include "LadderButtonConfig.h"
26 #include "AceButton.h"
28 namespace ace_button {
33 const uint16_t levels[],
36 uint8_t defaultReleasedState
39 mNumLevels(numLevels),
40 mNumButtons(numButtons),
41 mPressedState(defaultReleasedState ^ 0x1),
45 for (uint8_t i = 0; i < mNumButtons; i++) {
55 return (virtualPin == pin) ? mPressedState : (mPressedState ^ 0x1);
61 for (uint8_t i = 0; i < mNumButtons; i++) {
63 if (button ==
nullptr)
continue;
67 uint8_t buttonPin = button->
getPin();
68 uint8_t buttonState = (buttonPin == virtualPin)
69 ? mPressedState : (mPressedState ^ 0x1);
75 uint16_t level = analogRead(mPin);
76 return extractIndex(mNumLevels, mLevels, level);
79 uint8_t LadderButtonConfig::extractIndex(uint8_t numLevels,
80 uint16_t
const levels[], uint16_t level) {
83 for (i = 0; i < numLevels - 1; i++) {
90 uint16_t threshold = (levels[i] + levels[i+1]) / 2;
92 if (level < threshold)
return i;