Want larger center zone on potentiometer for motor control

Hi all,

I am currently working on a project that will control long/lat motors on a machine lathe. This will be done by two methods...either RC control through 2.4 ghz receiver using pulsein or hardwired control using potentiometers to control motors (depending on position of switch). Presently hardwired method is working well except I would like to have more of a center zone where the motors are commanded to stop. I have the arduino interfaced with a sabertooth 2x25 using the serial packetized method. So far I am having no luck with my attempts. The program was taken from another writer and I have modified it extensively to suit my needs. Anyone have any info??? Pretty sure I am missing something simple!

Thanks all R. Morgan

The IDE has a CTRL-T command to auto-layout the code.

Please modify your post, select the code and press the # button to get it proper tagged,

At least that makes it more readable :slight_smile:

Better redo the map function;

sensorValue_long = analogRead(sensorPin1);
sensorValue_lat = analogRead(sensorPin2);

To stabilize analogread() you can read multiple times and do some averaging.

int val = 0;
for (int i=0; i< 16; i++) val += analogRead(sensorPin1); 
sensorValue_long = val/16;

val = 0;
for (int i=0; i< 16; i++) val += analogRead(sensorPin2); 
sensorValue_lat= val/16;

The map function is for lineair interpolation, If you want to make a bigger deadzone the map() function is not usefull anymore.
Check the multimap function - http://arduino.cc/playground/Main/MultiMap - as this allows you to do multiple mappings in one.

Succes,
Rob

Sorry for the above post...Could not get the code to copy over with the proper formatting (only worked with the quote option). I included some conditional statements not complete yet to satisfy overtravel requirements, however, this is the code as it currently stands. Thanks Rob...I am in the process of modifying it per your suggestions. Any advice for the posting code since everyone else seems to be doing it properly.

You could just alter the analogRead output for a centre zone:

  int v = analogRead (...) - 512 ;  // get zero-centred reading
  if (v < -50)     v += 50 ;
  else if (v > 50) v -= 50 ;
  else             v = 0 ;

Thereafter any map calls would use the range -462 to +461

Thank you Mark and Rob. Following your advice I was able to solve the issue. I now have a beautiful "dead" spot in the center of the pots. Unfortunately with the new code it exceeds the maximum allowed in post so I can't list it until I get this posting issue resolved. Wish you were closer so I could buy yous a beverage.

Cheers, R. Morgan