I changed more code and it compiles just fine but no matter what values I change the servo does not move at all. Is this really this hard or am I just that bad at this. I was on a pretty good success run til now. Here is the sketch again with changes.
Code: Select all
#include <Servo.h>
#define READ_PIN 13
#define PWM_OUTPUT 10
int servoPos = map(500, 500, 10000 , 0, 10);
static double duty;
static double freq;
static long highTime = 0;
static long lowTime = 0;
static long tempPulse;
Servo myservo; // create servo object to control a servo
void setup()
{
myservo.attach(10); // attaches the servo on pin 9 to the servo object
pinMode(READ_PIN,INPUT);
Serial.begin(9600);
analogWrite(PWM_OUTPUT,230);
}
void loop()
{
readPWM(READ_PIN);
Serial.println(freq);
Serial.println(duty);
myservo.write(servoPos); // sets the servo position according to the scaled value
}
//Takes in reading pins and outputs pwm frequency and duty cycle.
void readPWM(int readPin)
{
highTime = 0;
lowTime = 0;
tempPulse = pulseIn(readPin,HIGH);
if(tempPulse>highTime)
{
highTime = tempPulse;
}
tempPulse = pulseIn(readPin,LOW);
if(tempPulse>lowTime)
{
lowTime = tempPulse;
}
freq = ((double) 1000000)/(double (lowTime+highTime));
duty = (100*(highTime/(double (lowTime+highTime))));
}
Perhaps you can offer some direction on what to change, I really want to get this on my own but am at a loss.
I also have a question, I thought the xBee output was PWM ? Isnt that what servos need for movement? Can you explain why the servo sketch does not work.