int motor1Pin1 = 27; 
int motor1Pin2 = 26; 
int enable1Pin = 14; 
String message;

// Setting PWM properties
const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;
int dutyCycle = 200;

void setup() {
  // sets the pins as outputs:
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);
  
  // configure LED PWM functionalitites
  ledcSetup(pwmChannel, freq, resolution);
  
  // attach the channel to the GPIO to be controlled
  ledcAttachPin(enable1Pin, pwmChannel);

  Serial.begin(115200);

  // testing
  Serial.print("Testing DC Motor...");
}

void loop() {
  
  while (Serial.available()>0){
  delay(10);
  char d = Serial.read();
  message += d;
  }
  if (message.length()>0){
    Serial.print(message);

    if (message == "fwd"){
      fwd ();
    }

    else if (message == "stp"){
      stp ();
    }

    else if (message == "back"){
      back();
    }

    else if (message == "inc"){

    }
  
  }
  //message = "";
}
  
  void fwd (){
    Serial.println("Moving Forward");
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH); 
  }
  
  void stp (){
    Serial.println("Moving Forward");
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW); 

  }

  void back (){
    Serial.println("Moving Backwards");
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW); 
  }