---
# System prepended metadata

title: "\nclass motor\n"

---

<h1>
class motor
</h1>

```arduino=
class motor
{
  const int ENA;
  const int ENB;
  const int IN1;
  const int IN2;
  const int IN3;
  const int IN4;
  
public:
  motor();
  void power(int);
  void goStraight();
  void goBack();
  void leftTurn();
  void rightTurn();
  void _stop();
};

motor::motor(int a, int b, int c, int d, int e, int f)
  :ENA(a), ENB(b), IN1(c), IN2(d), IN3(e), IN4(f)
{
   pinMode(ENA, OUTPUT);
   pinMode(ENB, OUTPUT);
   pinMode(IN1, OUTPUT);
   pinMode(IN2, OUTPUT);
   pinMode(IN3, OUTPUT);
   pinMode(IN4, OUTPUT);
}

motor::void power(int P)
{
  if(P > 255)
    P =255;
   else if(P < 0)
    P =0;
  
  analogWrite(ENA, P);
  analogWrite(ENB, P);
}

motor::void goStraight()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

motor::void goBack()
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

motor::void leftTurn()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

motor::void rightTurn()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

motor::void _stop()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}
```