hello guys,
Arduino i am using is Arduino Duemilanove just for the record,
well now i almost finished my circuit about driving a motor, the mechanism is using a throttle and brakes
what i want to do is this :
when i throttle, i need the motor to get fast as long as i turn the pot more till 1023
and for the brake when i turn the braking pot i need the motor speed to get low as long as i turn till 1023 we can say like the real brakes as long as you push the friction gets high till the car stop
so what is happening is this :
when i turn the throttle pot nothing happened untill i reach the 1023 (seems like a digital signal here !!)
as for the brakes, when i start turning the brake pot, the speed of the motor gets down bit by bit till it stops (this one works same as i wanted it, perfect)
one more problem is : now i am using A0 pin for brake and A1 pin for throttle
but first i had A0 for the throttle and A1 for brakes but the A0 pin is ignoring what i am telling it to do in the codes and always acting like brake and A1 as throttle so i had to flip the values A1 for throttle and A0 for brakes !!
does anyone have any idea what might be going on here ?
here are my codes :
int enablePin = 11; //PWM
int in1Pin = 10; //PWM
int in2Pin = 9; //PWM
int potPin1 = A1;
int potPin2 = A0;
void setup()
{
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
}
void loop()
{
int throttle = analogRead(potPin1);
throttle = map(throttle, 0, 1023, 255, 0);
int brake = analogRead(potPin2);
brake = map(brake, 0, 1023, 10, 0);
setMotor(throttle, brake);
}
void setMotor(int throttle, int brake)
{
int pedal ;
if(throttle){
pedal = throttle;
analogWrite(enablePin, throttle);
}else if (brake){
pedal = brake;
analogWrite(enablePin, brake);
}
digitalWrite(in1Pin, throttle);
digitalWrite(in2Pin, brake);
}