How disable serial communication pins 0 & 1

Hello all,

From the following code you will see that I am trying to use PWM on pins 0 & 1 on an Arduino Mega 2560, which I think is possible as long as they are not used for Tx and Rx. I know that communication is required for uploading the code but after that point there is nothing in my code that is a serial function. How can I disable Tx and Rx so I can use PWM on pins 0 & 1?

void setup () {
  
  for (int motorA = 22; motorA < 37; motorA++) {
    pinMode (motorA, OUTPUT);
  }
  for (int motorB = 37; motorB < 54; motorB++) {
    pinMode (motorB, OUTPUT);
  }
  for (int motorPWM = 0; motorPWM < 14; motorPWM++) {
    pinMode (motorPWM, OUTPUT);
    
       
  }
}




void loop () {
  
  for (int motorA = 22; motorA < 37; motorA++) {
    digitalWrite(motorA, HIGH);
  }
  
  for (int motorB = 37; motorB < 54; motorB++) {
    digitalWrite(motorB, LOW); }
    

 for (int motorPWM = 0; motorPWM <= 14; motorPWM++) {
    analogWrite(motorPWM, 5);

}

Many thanks,

Pete

What makes you think you can do PWM on Pins 0 and 1?

From Variants/Mega/pins_Arduino.h:

...
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
	// TIMERS		
	// -------------------------------------------		
	NOT_ON_TIMER	, // PE 0 ** 0 ** USART0_RX	
	NOT_ON_TIMER	, // PE 1 ** 1 ** USART0_TX	
	TIMER3B	, // PE 4 ** 2 ** PWM2	
	TIMER3C	, // PE 5 ** 3 ** PWM3	
	TIMER0B	, // PG 5 ** 4 ** PWM4	
	TIMER3A	, // PE 3 ** 5 ** PWM5	
	TIMER4A	, // PH 3 ** 6 ** PWM6	
	TIMER4B	, // PH 4 ** 7 ** PWM7	
	TIMER4C	, // PH 5 ** 8 ** PWM8	
	TIMER2B	, // PH 6 ** 9 ** PWM9	
	TIMER2A	, // PB 4 ** 10 ** PWM10	
	TIMER1A	, // PB 5 ** 11 ** PWM11	
	TIMER1B	, // PB 6 ** 12 ** PWM12	
	TIMER0A	, // PB 7 ** 13 ** PWM13
...

From analogWrite() - Arduino Reference

On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 through 13.

I am trying to use PWM on pins 0 & 1 on an Arduino Mega 2560, which I think is possible as long as they are not used for Tx and Rx

Wrong!
A PWM output is linked in hardware to the timers. There is no timer that is linked to these pins.

You can bitbang on those pins only