Should I changedchange the Arduino Mega for thea Leonardo or thea Due to get better performance?
You didn't quite say what kind of performance gains you had in mind. Looking at your code, it doesn't have any particular needs to justify a fancier Arduino.
With that said, I wanted to highlight one particular aspect of atmega32uATmega32u / leonardoLeonardo that in my view made it a particularly interesting chip for mixed signal application: its adcADC unit features a pgaPGA (1x, 10x, 200x) in differentaldifferential mode with bipolar readings.
it can be quite handy for some applications.