in C this could be
sprintf(buffer, "%+04d%c", ((velocity==0) ? 0 : (55 + abs(velocity))), 'a'+channel)
velcotiy can be 0..200, channel 0..2. (with a "deadband" for the velocity)
So setting velocity for a to 100 and c to -140 you have to send "+100a-140c". b will be set to 0.
The M5 has very limited resources, so I could not use Legoino, but used the information I found there to implement the button callback for the LEGO remote. The idea was to build the M5 directl in to the trains.
I used platform.io, since Visual Sudio Code offers more C/C++ extensions and features than the Arduino IDE. But you need to install the Arduino IDE also, as it is used in the background to build everything. So you should be able to use the code with the Arduino IDE.