엔코더 모터 입력한 각도만큼 움직이기
난폭한할아버지 | 2021-03-11
|
|
---|---|
const int motorDirPin3 = 8; //Dir은 방향 const int encoderPinA = 3; int encoderPos = 0; int value; const float ratio = 360. / 42. / 12.; void FA() { void FB() { void setup() { attachInterrupt(0, FA, CHANGE); pinMode(motorDirPin3, OUTPUT); Serial.begin(9600);
void loop() { while (!Serial.available()) {} value = Serial.parseInt(); Motor((value >= 0) ? HIGH : LOW, 0); Serial.print("encoderPos : "); void Motor(bool dir, int vel) { float Degree = (float)encoderPos * ratio; analogWrite(motorPWMPin, 0); while (!(value == Degree)) { digitalWrite(motorDirPin3, dir); if (vel == 0) { analogWrite(motorPWMPin, 0); }
제가 생각한 대로하여 360입력하면 한바퀴 돌고 끝나야하는데 왜 계속 도는지 모르겠습니다ㅠㅜ |
|
이전글 | 아두이노 업로드 문제 .. | 2021-02-27 |
다음글 | 도와주세요!! | 2021-03-20 |