ToneMelody works on any pin

Did you try on the hardware to see if it works? It shouldn't, at least not in a regular Arduino, which has PWM only on a few selected pins.