Hi all,
I'm trying to control two dc motors, like these http://img.diytrade.com/cdimg/472172/3499190/0/1224408480/Small_DC_Motor_for_electrical_tool_Toy_Hobby_Massage_machine.jpg
with two potentiometers (one slide and one turn).
I've hooked up the two motors like this: http://ardx.org/src/circ/CIRC03-sheet-OOML.pdf
I can control both the motors with the potentiometers, separately.
So when I comment out one of the functions in the void loop, everything works fine.
But, when both functions are "on", a change in one of the potentiometers, makes BOTH motors turn.
And they just keep turning for a random amount of time.
My goal is to achieve that I can just control the motors, at the same time, but with the two different potentiometers.
The code:
// 2 motors controlled by 2 pots
int motor1Pin = 10;
int pot1Pin = A1;
int pot1Value = 0;
int motor2Pin = 9;
int pot2Pin = A0;
int pot2Value = 0;
void setup()
{
Serial.begin(9600);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
}
void loop()
{
sliderpotmotor();
potmotor();
}
void potmotor(){
pot1Value = analogRead(pot1Pin);
pot1Value = map(pot1Value, 0, 1024, 0, 255);
digitalWrite(motor1Pin, pot1Value);
// debug
//Serial.println(pot1Value);
}
void sliderpotmotor() {
pot2Value = analogRead(pot2Pin);
pot2Value = map(pot2Value, 0, 1024, 0, 255);
digitalWrite(motor2Pin, pot2Value);
// debug
//Serial.println(pot2Value);
}
Thanks in advance,
Regards,
Lars