//MOVING MOTORS AND CHANGE DIRECTION WITH PUSH BUTTON
//pin numbers
int BUTTON1 = D8;
//pin numbers assigned in the Xiao for the H bridge
int PWMA = D0; //PWM for the first motor
int AIN2 = D1; //input for the first motor
int AIN1 = D2; //input for the first motor
int STBY = D3;
int BIN1 = D4; //input for the second motor
int BIN2 = D5; //input for the second motor
int PWMB = D6; //PWM for the second motor
//LED pins
int LED1 = D9;

void setup() {
  //pin mode for the motors information
  pinMode(PWMA, OUTPUT);
  pinMode(AIN2, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(STBY, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
  pinMode(PWMB, OUTPUT);
  //pin mode for the button
  pinMode(BUTTON1, INPUT);
  //pin mode for the LED
  pinMode(LED1, OUTPUT);}

void loop() {
  //main code: PWM at maximum and both motors in a direction
  analogWrite(PWMA, 255);
  digitalWrite(AIN2, HIGH);
  digitalWrite(AIN1, LOW);
  digitalWrite(STBY, HIGH);
  digitalWrite(BIN1, LOW);
  digitalWrite(BIN2, HIGH);
  analogWrite(PWMB, 255);
  digitalWrite(LED1, HIGH);//LED turned on
  
  while(digitalRead(BUTTON1) == true){//signals push button
    digitalWrite(LED1, LOW);//turns LED off
    //change direction of the motors
    digitalWrite(AIN2, LOW);
    digitalWrite(AIN1, HIGH);
    digitalWrite(BIN1, HIGH);
    digitalWrite(BIN2, LOW);}}