Go Down

Topic: steering question (Read 677 times) previous topic - next topic

I am trying to change up some arduino code to accept potentiometer input for variable turn rate. This is what I have right now but I can only tell it turn or dont turn. I need help adding the potentiometer part to it.

//steer one way        SteerValue of 512 is straight ahead
  if (k2 == 1) {
              if (gangleratedeg2 < 5) {    //will turn clockwise at 5 degrees per sec and if not, more power fed into steering until it does
                                           SteerValue = SteerValue + 1;
                                                    }
              if (gangleratedeg2 > 5) {
                                           SteerValue = SteerValue - 1;
                                                    }               
              }
//change the 5 and -5 values if you want faster turn rates. Could use a potentiometer to control these values so would have proportional control of steering       
             
//steer the other way           
  if (k3 == 1) {
              if (gangleratedeg2 < -5) {    //will turn anticlockwise at 5 degrees per sec and if not, more power fed into steering until it does
                                           SteerValue = SteerValue + 1;
                                                    }
              if (gangleratedeg2 > -5) {
                                           SteerValue = SteerValue - 1;
                                                    }
              } 
   
    if (SteerValue < 1) {
                    SteerValue = 1;
                        }
    if (SteerValue > 1023) {
                    SteerValue = 1023;
                           } 
   
    SteerCorrect = 0;
    } 

AWOL

Difficult to say from such a brief snippet of code (please use the # icon in the editor's toolbar when posting code), but I think you're going to need to look at "analogRead" and "map".
http://arduino.cc/en/Reference/AnalogRead
http://arduino.cc/en/Reference/Map
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Goofballtech

Assuming you are using a servo (because your adjustments are listed in degrees) this page may also help.

http://www.arduino.cc/playground/ComponentLib/Servo


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy