Wednesday, 23 October 2019

Exp_Code_01

아두이노의 모터 속도를 조절하기 위한 코드를 작성하였다. 작성에는 이전의 작업 결과를 많이 참고하여 코딩을 작성하였다.

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 int dirPin = 4;
const int stepPin = 5;
const int enablePin = 6;

int customDelay, 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