아두이노의 모터 속도를 조절하기 위한 코드를 작성하였다. 작성에는 이전의 작업 결과를 많이 참고하여 코딩을 작성하였다.
I wrote the code to control the Arduino's motor speed. Coding was written by referring to previous works done by other people.
Code for Controlling the Stepper Motor (모터 조절을 위한 코드)
const intdirPin = 4;
const intstepPin = 5;
const intenablePin = 6;
intcustomDelay ,customDelayMapped ;
void setup( )
{
pinMode(enablePin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(enablePin, LOW);
digitalWrite(dirPin, HIGH);
}
void loop(){
customDelayMapped = speedUP();
digitalWrite ( stepPin, HIGH);
delayMicroseconds(customDelayMapped);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayMapped);
}
int speedUP(){
int customDelay = analogRead(A0);
int newCustom = map(customDelay, 0, 1023, 300, 4000);
return newCustom;
}
No comments:
Post a Comment