Apr 23, 2019

Pololu dual motor driver - DRV8835 - Arduino code (모터 드라이버)


- Simple Arduino code to operate two DC motors with the motor driver.
- 2개의 DC 모터를 구동시키기 위해 모터 드라이버를 이용하는 간단한 아두이노 코드.

/////////////////////////////////////////////////////////
//main code//
/////////////////////////////////////////////////////////

int left_motor_in = 3; //PWM pin
int left_motor_out = 7;

int right_motor_in = 11; //PWM pin
int right_motor_out = 12;

void setup() {
  // put your setup code here, to run once:
  pinMode(left_motor_in, OUTPUT);    pinMode(left_motor_out, OUTPUT);
  pinMode(right_motor_in, OUTPUT);  pinMode(right_motor_out, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  left_motor_go(100);
  right_motor_go(100);
}

/////////////////////////////////////////////////////////
//user function
/////////////////////////////////////////////////////////

// 0<parameter value<255
void left_motor_go (int motor_speed) {
  analogWrite(left_motor_in, motor_speed);
  digitalWrite(left_motor_out, LOW);
}

void right_motor_go (int motor_speed) {
  analogWrite(right_motor_in, motor_speed);
  digitalWrite(right_motor_out, LOW);
}

No comments:

Post a Comment