Hallo Zusammen,
ich habe eine ganz kurze Frage über die Steuerung eines Motors mittels Arduino und Encoder.
Das Programm was ich jetzt verwende hat die Funktion,dass der motor einen Schritt erfüllt solange der Encoder einen Schritt gemacht hat.
jetzt die Frage wie kann ich eine komplette Umdrehung des Motors mit nur einem Schritt vom Encoder eingeben ?
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
// defines pins numbers
#define stepPin 3
#define dirPin 10
#define outputA 8
#define outputB 9
int counter = 0;
int angle = 0;
int aState;
int aLastState;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
aLastState = digitalRead(outputA);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
}
void loop() {
aState = digitalRead(outputA);
if (aState != aLastState){
if (digitalRead(outputB) != aState) {
counter ++;
angle ++;
rotateCW();
}
else {
counter--;
angle --;
rotateCCW();
}
if (counter >=30 ) {
counter =0;
}
lcd.clear();
lcd.print("Position: ");
lcd.print(int(angle*(-1.8)/360));
lcd.print("deg");
lcd.setCursor(0,0);
}
aLastState = aState;
}
void rotateCW() {
digitalWrite(dirPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(0);
digitalWrite(stepPin,LOW);
delayMicroseconds(0);
}
void rotateCCW() {
digitalWrite(dirPin,HIGH);
digitalWrite(stepPin,HIGH);
delayMicroseconds(0);
digitalWrite(stepPin,LOW);
delayMicroseconds(0);
}
Danke