ATTN: mem-
I chose those values because when I tested the pot, those are it's limits. At one end it stays at aou 311, and at the other it stays around 445. I retested a few times, and it's ends fluctuate everytime I upload new code. Is there a way that I can stop this from happening, or write in some code to manually set it's limits once the program is already running? Also, the data coming from the pot has a bit of jitter on it. Can I smooth this out somehow?
I Checked the highest spikes from the pot and accounted accordingly for them. I'll take that line out, limit the servo range even further to it's inner 90deg (I'm already about 10% in an each end) and see how it works. also, does map work as I think it does? Here's what I think happens.
var = map(var, A1, B1, A2, B2);
Where A1 and B1 are the initial endpoints, and A2 and B2 are the finl points the data is stretched to.
ATTN: Gnu-
In the first post I explain that I'm building a quadruped, and for purposes of agility and other uses (a walking cnc machine if I can get the math right). I'll be building my own power management circuit with the help of a friend (this is becoming a team build at the dorm). What is this precision timer of which you speak, and why would we need one?
Latest code:
int servoPin = 8; //Naming the pin for the servo
int potPin = 2; //Naming the pin for the potentiometer
int pos = 600; //Decloring an initial value for "pos",
// "pos" will be rewritten before 600 can be used
void setup() //Declaring the usage of each pin
{
pinMode(servoPin, OUTPUT); //Set the Servo's pin as an output
pinMode(potPin, INPUT); //Set the Potentiometer's pin as an input
Serial.begin(9600); //Set the data rate for serial communications at 9600
}
void loop() //The actual running loop
{
pos = analogRead(potPin); //Reading the position of the pot and saving it as "pos"
Serial.println(pos); //Tell me where the servo is
pos = map(pos, 310, 370, 1050, 1950); //Changing the pot's data into the impulse length
//Serial.println(pos); //Tell me where the servo is
digitalWrite(servoPin, HIGH); //Start the servo's impulse
delayMicroseconds(pos); //The impulse length as determined by the value of "pos"
digitalWrite(servoPin, LOW); //End the servo's impulse
pos = map(pos, 600, 2400, 0, 180); //Turn the impulse length into degrees
//Serial.println(pos); //Tell me where the servo is
delay(15); //Allow the servo to get to it's desired position
}