i would like to be able to control the speed and direction of a motor with a pot
the method would be to use the first half of pot rotation to run the motor in one direction and control its speed and in the in the second half of pot rotation run the motor in the other direction and control its speed
in the middle of the pots rotation the motor would be stopped and increase in speed in either direction of pot rotation
the mechanical analogue would be a disk driving a wheel that traveled from one side of the diameter to the other, increasing in speed as the wheel traveled from middle to edge and stopping as the wheel was in the middle of the disk
i would like to be able to set variables for min and max speed of the wheel and set the the zone on the pot of no speed
any ideas
i have a arduion uno r3 , i have a motor controller shield (Adafruit Motor/Stepper/Servo Shield for Arduino v2.3 Kit) and pots on order
in all my searching online i haven't come across anything quite like this
from what i've read mapping will take care of half of what i want, not sure about the other half that would require decrementing
Doesn't sound hard.
Read a pot, values from 0 to 506 control PWM to H-bridge one direction, values from 518 to 1023 control H-bridge the other direction. Change dead spot as needed.
0 to 512 = 10 bits, you need 8 bits for PWM, so just take a reading and manipulate as needed:
speedBase = analogRead(A0);
if (speedBase<=511){
lowSpeed = speedBase >>1; // now it's 8-bits, 0 to 255
// however 0 is desired for high speed, so subtract it from 255
lowSpeed = 255 - lowSpeed;
analogWrite (highspeedEnablePin, 0); // turn off the other side
analogWrite (lowspeedEnablePin, lowSpeed); // turn motor the other direction.
}
if (speedBase>=512){ // other side 512 to 1023
offset set for 0 to 511
highSpeed = highSpeed - 512; // now 0 to 511
highSpeed = highSpeed >>1; // and 0 to 255
analogWrite (lowspeedEnablePin, 0); // turn off the other side
analogWrite (highspeedEnablePin, highSpeed); // turn motor the other direction
}
I don't know if you need to give the motor a chance to slow down before changing direction, might see big current jump if not.
I wrote as two ifs so you can open the ranges a little for dead band.
i appriciate your time and effort and i'm not doubting you as i don't know much about the arduino only having just got one and waiting for the pots and motor controller
here is a link to what i'm trying to copy, it starts at 30:45 to 35:30
i'd like the motor to respond as though it were the mechanical system i described
I suggest to wait until your parts arrive, put it all together and try out CrossRoad's suggested code. Then you can judge whether it does what you want, and if not, modify it to suit.
There is nothing unusual about your proposed controller.