Control Surface - Background Ping Sending

Hello everyone!

I came across this doc which recommends to send a ping (note on, key 0, velocity 0) every two seconds to make sure the control surface is connected to the device.

Sending a ping should be quite simple (note on, key 0, velocity 0), hex: 90 00 00.
However, would it be possible to keep sending pings in the background without interfering with the rest of the script?

I'm trying to figure out what to do based on this page:

But basically the function to call every 2000ms would be this:

  Control_Surface.send(ChannelMessage{0x90, 0x00, 0x00});

Am I on the right path?
Thanks

You might want to research the millis() function and examples.

(Untested)

#include <Control_Surface.h>

USBMIDI_Interface midi;

void setup() {
  Control_Surface.begin();
}

void loop() {
  static AH::Timer<millis> ping_timer {2000};
  if (ping_timer)
    Control_Surface.sendNoteOn(0, 0);
  Control_Surface.loop();
}

Thanks a lot @PieterP
It works!