MIDI programming best practices

I am adding MIDI to a pedalboard using the Arduino Leonardo because it has built-in USB communication and will be detected as a USB device by the computer.
What are the best practices for sending MIDI commands to HW?
For example. the simplest program would continuously scan the pedalboard and send a note-on command if the key is pressed and a note-off if the key is not pressed. This generates a constant stream of data, not a lot of bandwidth used but seems like over kill.
1. Should I check for the prior status of the note and only send commands when there is a change?
2. If I do #1 and no keys are pressed, then no commands are sent. How will the software detect the midi device? Is it sufficient to just send commands during the initial Midi input setup and HW will remember the midi device? Does it ever forget MIDI devices, i.e. when HW is restarted>
3. do I need to send a MIDI command periodically, (every x seconds) so that the MIDI device will be detected? I could send the All Notes Off command if no keys are pressed
What are the best practices for sending MIDI commands to HW?
For example. the simplest program would continuously scan the pedalboard and send a note-on command if the key is pressed and a note-off if the key is not pressed. This generates a constant stream of data, not a lot of bandwidth used but seems like over kill.
1. Should I check for the prior status of the note and only send commands when there is a change?
2. If I do #1 and no keys are pressed, then no commands are sent. How will the software detect the midi device? Is it sufficient to just send commands during the initial Midi input setup and HW will remember the midi device? Does it ever forget MIDI devices, i.e. when HW is restarted>
3. do I need to send a MIDI command periodically, (every x seconds) so that the MIDI device will be detected? I could send the All Notes Off command if no keys are pressed