I got the code working now. I got confused by a photo of Arduino Mega 2560 R3 board with labeled pinouts. Are pins 23, 25, 27, and 29 digital pins, not 5V pins? I think that two pins over pins 22 and 23 on the double header on the right side of the board are 5V pins.
int InA1 = 22;
int InB1 = 24;
int PWM1 = 4;
int InA2 = 26;
int InB2 = 28;
int PWM2 = 5;
int InA3 = 30;
int InB3 = 32;
int PWM3 = 6;
int InA4 = 34;
int InB4 = 36;
int PWM4 = 7;
int switch01 = 38;
int switch02 = 39;
int switch03 = 40;
int switch04 = 41;
int switch05 = 42;
int switch06 = 43;
int switch07 = 44;
int switch08 = 45;
int switch09 = 46;
int switch10 = 47;
int switchstate01 = 0;
int switchstate02 = 0;
int switchstate03 = 0;
int switchstate04 = 0;
int switchstate05 = 0;
int switchstate06 = 0;
int switchstate07 = 0;
int switchstate08 = 0;
int switchstate09 = 0;
int switchstate10 = 0;
void setup()
{
Serial.begin(115200);
pinMode(InA1,OUTPUT);
pinMode(InB1,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(InA2,OUTPUT);
pinMode(InB2,OUTPUT);
pinMode(PWM2,OUTPUT);
pinMode(InA3,OUTPUT);
pinMode(InB3,OUTPUT);
pinMode(PWM3,OUTPUT);
pinMode(InA4,OUTPUT);
pinMode(InB4,OUTPUT);
pinMode(PWM4,OUTPUT);
pinMode(switch01,INPUT);
pinMode(switch02,INPUT);
pinMode(switch03,INPUT);
pinMode(switch04,INPUT);
pinMode(switch05,INPUT);
pinMode(switch06,INPUT);
pinMode(switch07,INPUT);
pinMode(switch08,INPUT);
pinMode(switch09,INPUT);
pinMode(switch10,INPUT);
}
void loop()
{
switchstate01 = digitalRead(switch01);
switchstate02 = digitalRead(switch02);
switchstate03 = digitalRead(switch03);
switchstate04 = digitalRead(switch04);
switchstate05 = digitalRead(switch05);
switchstate06 = digitalRead(switch06);
switchstate07 = digitalRead(switch07);
switchstate08 = digitalRead(switch08);
switchstate09 = digitalRead(switch09);
switchstate10 = digitalRead(switch10);
if (switchstate01 == HIGH)
{
digitalWrite(InA1,HIGH);
digitalWrite(InB1,LOW);
analogWrite(PWM1,255);
Serial.print("Switch 1 HIGH ");
}
if (switchstate02 == HIGH)
{
digitalWrite(InA1,LOW);
digitalWrite(InB1,HIGH);
analogWrite(PWM1,255);
Serial.print("Switch 2 HIGH ");
}
if (switchstate01 == LOW && switchstate02 == LOW)
{
analogWrite(PWM1,0);
Serial.print("Switch 1 & 2 LOW ");
}
if (switchstate03 == HIGH)
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 3 HIGH ");
}
else
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 3 LOW ");
}
if (switchstate04 == HIGH)
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.print("Switch 4 HIGH ");
}
else
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.print("Switch 4 LOW ");
}
if (switchstate05 == HIGH)
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 5 HIGH ");
}
else
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 5 LOW ");
}
if (switchstate06 == HIGH)
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.print("Switch 6 HIGH ");
}
else
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.print("Switch 6 LOW ");
}
if (switchstate07 == HIGH)
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 7 HIGH ");
}
else
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 7 LOW ");
}
if (switchstate08 == HIGH)
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.print("Switch 8 HIGH ");
}
else
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.print("Switch 8 LOW ");
}
if (switchstate09 == HIGH)
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 9 HIGH ");
}
else
{
//digitalWrite(InA1,LOW);
//digitalWrite(InB1,HIGH);
//analogWrite(PWM1,255);
Serial.print("Switch 9 LOW ");
}
if (switchstate10 == HIGH)
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.println("Switch 10 HIGH ");
}
else
{
//digitalWrite(InA1,HIGH);
//digitalWrite(InB1,LOW);
//analogWrite(PWM1,255);
Serial.println("Switch 10 LOW ");
}
/*
digitalWrite(InA2,LOW);
digitalWrite(InB2,HIGH);
analogWrite(PWM2,0);
digitalWrite(InA3,LOW);
digitalWrite(InB3,HIGH);
analogWrite(PWM3,0);
digitalWrite(InA4,LOW);
digitalWrite(InB4,HIGH);
analogWrite(PWM4,0);
*/
}