artvantriest:
bummer
you know of someone who allready did this?
saves me some time programming...
YES I am lazy..
thnx...
Actually, if I'm understanding correctly, wouldn't be too hard at all.
You'll be using a motor controlller, easiest way will be to use a PWM method of input to dictate speed and directions. Now, you didn't indicate what you will be using to control the motors.
Keep in mind that you'll still need to use analogRead to get the voltage coming out of the pot, and compare it to the dead band of where you're wanting to go.
Also, keep in mind the deadband req for the code i supply below (no working guarantees, either)
IF you're confused on the OR statements:
If the pot is less than 2.5 volts, it will be out of range. Therefore, you will want it to not be able to go further out of range, only into range. This would be the same direction of travel if it were approaching 4.25 volts.
If the pot is greater than 4.25 volts, it will be out of range. Therefore, you will only want it to be able to go further out of range, only into range. This would be the same direction of travel if it were approaching 2.5 volts.
Note that this method (the only method I can think of ATM), it will get VERY nasty when you start putting deadbands in. I can only hope somebody knows a better way.
Pseudo:
float pot1 = analogRead(voltage input for potentiometer);
float endpoint1 = 4.25; // V=IR, V= 5 volt, R = potentiometer (example is 425 ohms), I = 10mA
float endpoint2 = 2.5; // V=IR, V= 5 volt, R = potentiometer (example is 250 ohms), I = 10mA
void loop(){
if (condition that makes it rotate one direction){
if ((pot1 < endpoint1) || (pot1 < endpoint2)){ // if the pot is less than 4.25 volts OR less than 2.5 volts, motor can turn one direction only
digitalWrite(motordirectionPin, HIGH);
analogWrite(motorspeedPin, pulsewidth); //pulsewidth is from 0-255
} else {
analogWrite(motorspeedPin, 0);
} //endif deadband
} else if ((pot1 > endpoint2 || (pot1 > endpoint1)){ // if the pot is greater than 2.5 volts OR greater than 4.25 volts, motor can turn other direction only
if (we are not yet to the dead-band){
digitalWrite(motordirectionPin, LOW);
analogWrite(motorspeedPin, pulsewidth); //pulsewidth is from 0-255
} else {
analogWrite(motorspeedPin, 0);
} //endif deadband
} else { // If the unexpected happens
digitalWrite(motordirectionPin, LOW);
analogWrite(motorspeedPin, 0);
} //endif rotational direction
} // end loop()