I am in the process of building a autonomous yacht with proportional steering. The input for Proportion Control is taken from 5V Pot ( no stop ). This input is then sent to the output of a 180 degree servo motor. I have succeeded in controlling this system with a Arduino UNO. I want to control the same hardware on a Galileo in C. I have a test function wrote and will attach. In this function you can see how the full duty cycle is calculated but, what I want to do is input one figure to the function that will control the ON cycle and the OFF cycle. Any help would be appreciated.
Cheers,
John
Code:
***********************************************
void servoPWM(int);
int ON,OFF,x;
int servo = 9;
void setup(){
Serial.begin(9600);
pinMode(9,OUTPUT);
}
void loop()
{
int Dir;
//if(Dir==
for(Dir=-90;Dir<90;Dir++)
{
servoPWM(Dir);
delay(10);
}
for(Dir=90;Dir>-90;Dir--)
{
servoPWM(Dir);
delay(10);
}
}
void servoPWM(int Dir)
{
ON = map(Dir,-90,90,550,2250);
OFF = 20000 -ON;
digitalWrite(servo,HIGH);
delayMicroseconds(ON);
digitalWrite(servo,LOW);
delayMicroseconds(OFF);
Serial.print("Direction ");
Serial.println(Dir);
Serial.print("ServoON ");
Serial.println(ON);
Serial.print("ServoOFF ");
Serial.println(OFF);
}
***************************************************************************