creating a LOOPER #506
santta
started this conversation in
Show and tell
Replies: 2 comments 1 reply
-
Please, anyone have any ideas? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm afraid this is outside of the support I can give here, it might be more suitable for https://forum.arduino.cc. Be sure to ask specific questions about what you don't understand. Here's an example sketch: #include <Control_Surface.h>
class MultiPurposeButton {
public:
MultiPurposeButton(pin_t pin) : button(pin) {}
enum Event {
None, PressStart, ShortPressRelease, LongPress, LongPressRelease, SecondPressStart,
};
void begin() { button.begin(); }
Event update() {
Event event = None;
switch (button.update()) {
case Button::Released: {} break;
case Button::Falling: {
auto now = millis();
event = (now - pressStartTime <= secondPressDelay) ? SecondPressStart : PressStart;
pressStartTime = now;
} break;
case Button::Pressed: {
auto now = millis();
if (not longPress && now - pressStartTime >= longPressDelay) {
event = LongPress;
longPress = true;
}
} break;
case Button::Rising: {
event = longPress ? LongPressRelease : ShortPressRelease;
longPress = false;
} break;
}
return event;
}
private:
Button button;
unsigned long longPressDelay = 1000;
unsigned long secondPressDelay = 400;
unsigned long pressStartTime = -1ul - secondPressDelay ;
bool longPress = false;
public:
friend FlashString_t to_string(Event ev) {
switch (ev) {
case None: return F("None");
case PressStart: return F("PressStart");
case ShortPressRelease: return F("ShortPressRelease");
case LongPress: return F("LongPress");
case LongPressRelease: return F("LongPressRelease");
case SecondPressStart: return F("SecondPressStart");
default: return F("<invalid>");
}
}
};
MultiPurposeButton btn = 4;
void setup() {
Serial.begin(115200);
while (!Serial);
btn.begin();
}
void loop() {
MultiPurposeButton::Event event = btn.update();
if (event != MultiPurposeButton::None) {
Serial.println(to_string(event));
}
} A short press will result in the following events: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Pieter, hello, one of the modes of my Foot switch will be LOOPER (in my guitar VST amplitube5).
The instructions for its use state the following:
• Tap once: RECORD/OVERDUB/PLAY on the corresponding track.
• Double tapping: stop any playback or overdubbing on that track.
• Press & hold: erase the corresponding loop.
but it doesn't work from CCbutton and CCButtonLatched.
I've seen issues like this and you advised using the "LongPress" code.
Unfortunately, I could not master the code from your answer, could you describe in a little more detail how you can implement "Double tapping" and "Press & hold".
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions