Add more io

but I have doubts about the timing

So do I.
At 4000 RPM you have 66 rotations a second. For 40 motors you have 2666 pulses per second to time.
Using SPI is the fastest way to get inputs into the arduino but measuring those similtainousyl is going to be tricky, if not impossible.