Hi
I really need some help with my latest project.
my goal is to drive a gear box x amount of times x been 1800 revolutions at this time.
I have found a encoder library that works fine my problem is when I try to control the motor nothing happens with either serial print or the motor my code is as follows
Thanks in advance
#include <Encoder.h>
#include <AFMotor.h>
AF_DCMotor motor(4);
int dp;
// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(2, 3);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}
long oldPosition = -999;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
motor.setSpeed(200);
motor.run(FORWARD);
while (newPosition<=1800);
motor.run(RELEASE);
}
}