아두이노

motor driver

내동 2020. 7. 12. 15:54

R_En-->7번핀연결,  L_EN-->8번핀연결

R_PWM---> 5번핀연결  L_PWM-->6번핀연결

 

BTS7960 motor drover

#define LEFT true

#define RIGHT false

 

 

void setup(){

for(int i= 5; i<9; I++){

pinMode( i, OUTPUT);}

for(int i =5; I <9 ; I++) {

digitalWrite( I , LOW) ;}

motorON (LEFT);

}

void loop() {

MC(LEFT, 50); delay(1000); motorON(LEFT); delay(1000);

MC(RIGHT,50); delay(1000); MOTORon(LEFT) ; delay(1000);

}

 

void MC( bool a, toPWM( mspeed){

if( a==LEFT) { digitalWrite(5,LOW);

analogWrite(6, toPWM( mspeed));}

else{ digitalWrite(6,LOW);

analogWrite( 5, toPWM( mspeed));}

}

void motorON( bool a) {

if ( a==LEFT){ digitalWrite (7,HIGH); digitalWrite (8,HIGH);}

else{digitalWrite (7,LOW); digitalWrite (8,LOW);}

}

 

int toPWM( int v){

return map( v, 0,100, 0, 255);}

 

'아두이노' 카테고리의 다른 글

건널목신호대  (0) 2020.11.29
세탁기 코드  (0) 2020.08.19
class 사용하기  (0) 2020.07.12
segway  (0) 2020.05.04
불루트스로 DC 모터 제어하기  (0) 2020.03.28