Hiya, folks!
I've got a footswitch button connected to my Teensy 2.0 and this code is working beautifully, except for one thing: I'd like the "PLAY START" function to start a few milliseconds after the button's been pressed. I'm very, VERY new at this, but from my research it seems like "delay()" is the simplest and best option for me. However, no matter where I place that code, it doesn't work the way I need it to. I've tried putting "delay(1000)" beneath almost every line in the code (see below), one line at a time, and either:
All of the above seems to only depend on where the "delay(1000)" code is placed, but I can't make heads nor tails of it. I know I'm missing something; this seems like it should be really simple. Is anyone able to lend a noob like me a hand with this?
TIA!
Here's the code:
I've got a footswitch button connected to my Teensy 2.0 and this code is working beautifully, except for one thing: I'd like the "PLAY START" function to start a few milliseconds after the button's been pressed. I'm very, VERY new at this, but from my research it seems like "delay()" is the simplest and best option for me. However, no matter where I place that code, it doesn't work the way I need it to. I've tried putting "delay(1000)" beneath almost every line in the code (see below), one line at a time, and either:
- nothing happens,
- the target will play immediately, go for 1 second and then stop (whereas I *want* it to wait for 1 second and then START playing), or
- I can see that the target is receiving a message of some kind (an indicator light flashes) 1 second after the button is pressed, but then nothing else happens (no play start, etc.).
All of the above seems to only depend on where the "delay(1000)" code is placed, but I can't make heads nor tails of it. I know I'm missing something; this seems like it should be really simple. Is anyone able to lend a noob like me a hand with this?
TIA!
Here's the code:
Code:
#include <Arduino.h>
#include "Button.h"
#define BUTTON_1 PIN_B0
Button *buttons[1];
void setup() {
buttons[0] = new Button(BUTTON_1);
}
void sendMMC(uint16_t length, uint8_t* msg) {
static uint8_t buffer[20] = { 0xf0, 0x7f, 0x7f, 0x06 };
memcpy(buffer + 4, msg, length);
buffer[length + 4] = 0xf7;
usbMIDI.sendSysEx(length + 5, buffer, true);
}
void loop() {
if (buttons[0]->update()) {
// PLAY START
if (buttons[0]->wasPressed()) {
sendMMC(1, (uint8_t*)"\x02"); // Play
}
// RESET
if (buttons[0]->wasLongPressed()) {
sendMMC(1, (uint8_t*)"\x01"); // Stop
sendMMC(8, (uint8_t*)"\x44\x06\x01\x00\x00\x00\x00\x00"); // Locate zero
}
}
while (usbMIDI.read()) {} // ignore incoming messages
}