Hello there! I'm new to the ardunio, I have to create a way to drive a stepper motor with a potentiometer, ie for each angle of the potentiometer is moved an angle equal to the stepper motor which will have a second pot to Feedback. Using a dedicated driver Polulu that I generate pulses on a pin and another pin I generate a pulse direction, which goes to a HIGH and LOW direction goes to another.
As follows in the drawing down there.
Thank you if you can help me.
Ai down a code that did this to test the analog inputs and some variables, then not progressed more.
Thanks
int PotMan = A0;
int PotMot = A1;
int StepPin = 2;
int DirPin = 3;
int ValorManete = 0;
int ValorMotor = 0;
int v1=0;
void setup() {
pinMode(StepPin, OUTPUT);
pinMode(DirPin, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
}
void loop()
{
ValorManete = PotMan;
ValorManete = analogRead(PotMan);
{
ValorManete = analogRead(PotMan);
ValorManete = map(ValorManete, 0, 1023, 0, 630);
}
{
digitalWrite(StepPin, LOW);
if ( ValorManete <= 1 )
{
digitalWrite(StepPin, HIGH);
}
{
digitalWrite(StepPin, LOW);
{v1 = constrain(v1, 300, 500);}
if ( ValorManete == v1 )
{
digitalWrite(StepPin, HIGH);
}
}
{
digitalWrite(StepPin, LOW);
if ( ValorManete >= 629)
{
digitalWrite(StepPin, HIGH);
}
}
{
ValorMotor = PotMot;
ValorMotor = analogRead(PotMot);
{
ValorMotor = analogRead(PotMot);
ValorMotor= map(ValorMotor, 0, 1023, 0, 315);
}
{
digitalWrite(DirPin, LOW);
if ( ValorMotor <= 1 )
{
digitalWrite(DirPin, HIGH);
}
}
{
digitalWrite(DirPin, LOW);
if ( ValorMotor >= 315 )
{
digitalWrite(DirPin, HIGH);
}
}
}
}
}