basically, the whole program need to be redo since the hardware have been change.
go to this Arduino Playground - Bounce and download the library.
change the for the switch from port 3 to port 4 cause port 3 is use to control the stepper pwm_cha.
#include <Bounce.h>
#include <Stepper.h>
const int num_step = 50; // motor steps per revolution
const int pwm_cha = 3;
const int pwm_chb = 11;
const int dir_cha = 12;
const int dir_chb = 13;
const int brake_cha = 9;
const int brake_chb = 8;
const int Pin1=2;
const int Pin2=4;
Stepper stepper(num_step, dir_cha, dir_chb);
Bounce B1 = Bounce( Pin1,5 );
Bounce B2 = Bounce(Pin2,5);
void setup()
{
Serial.begin(9600);
pinMode(pwm_cha, OUTPUT);
pinMode(pwm_chb, OUTPUT);
pinMode(brake_cha, OUTPUT);
pinMode(brake_chb, OUTPUT);
digitalWrite(pwm_cha, HIGH);
digitalWrite(pwm_chb, HIGH);
digitalWrite(brake_cha, LOW);
digitalWrite(brake_chb, LOW);
pinMode(Pin1,INPUT);
pinMode(Pin2,INPUT);
digitalWrite(Pin1,HIGH);
digitalWrite(Pin2,HIGH);
}
void loop()
{
B1.update ( );
B2.update ( );
int ValB1=!B1.Read();
int ValB2=!B2.Read();
if (ValB1 &&!ValB2)
{digitalWrite(pwm_cha, HIGH);digitalWrite(pwm_chb, HIGH);
stepper.step(spr);stepper.setSpeed(400);}
if(!ValB1&&ValB2)
{digitalWrite(pwm_cha, HIGH);digitalWrite(pwm_chb, HIGH);
stepper.step(-spr);stepper.setSpeed(400);}
if ( !ValB1 && !ValB2){digitalWrite(pwm_cha, LOW);digitalWrite(pwm_chb, LOW);}
}