I'm learning... 2nd day user
read lots of posts trying to match my problem but was not successful.
Uno
Motor Shield
12v 7amp battery
DC motor
10k potentiomter
I'm simply trying to change the direction of the motor with the pot but with the Motor Shield connected to the Uno the serial monitor is showing me values from 2 to 1013 from the pot. It moves from 2 to 40 ish and then jumps to 1000. I never see any values between 40 ish and 1000. When I have the Motor Shield disconnected and pot connected to the same pins using the same code I get the desired results of 0-1023 from the pot in the Serial Monitor. What i see in the Serial Monitor is what I'm seeing with the motor operation.
code:
void setup() {
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A
pinMode(9, OUTPUT); //Initiates Brake Channel A
pinMode(A0, INPUT);
digitalWrite(9, LOW); //Disengage the Brake
digitalWrite(12, LOW); //Set direction
analogWrite(3, 255); //Channel A at full speed
Serial.begin(9600); //setup serial monitor
}
void loop() {
int potval = analogRead(A0);
delay(30);
Serial.println(potval);
delay(1); // delay in between reads for stability
//map values
potval = map(potval, 0, 1023, -255, 255);
if (potval < 0) {
//spin left
digitalWrite(12, HIGH);
}
else {
//spin right
digitalWrite(12, LOW);
}
//val without sign
int abso = abs(potval);
//constrain it to 0-255 to be sure
constrain(abso,0,255);
//set speed
analogWrite(3, abso);
// Serial.println(abso);
//delay(1000); // delay in between reads for stability