Hello all,
I am now trying to control multiple servos each by a flex sensor. i have successfully got the first flex with one servo working, however, i cant seem to get it working when i try it with two servos. any idea or suggestion as to how i could achieve this? im trying to control 5 servos using 5 flex sensor. also i dont believe there is anything wrong with the circuit or hardware as it all worked fine. im assuming its a firmware/software problem.
here is my code:
I am now trying to control multiple servos each by a flex sensor. i have successfully got the first flex with one servo working, however, i cant seem to get it working when i try it with two servos. any idea or suggestion as to how i could achieve this? im trying to control 5 servos using 5 flex sensor. also i dont believe there is anything wrong with the circuit or hardware as it all worked fine. im assuming its a firmware/software problem.
here is my code:
C:
unsigned int Adcval;
unsigned int Adcval2;
unsigned int i,a;
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void servoRotate0() //0 Degree
{
//unsigned int i;
PORTB.F0 = 1;
Delay_us(500);
for(i=0;i<Adcval;i++)
{
Delay_us(1);
}
PORTB.F0 = 0;
Delay_us(19500);
}
void servoRotate1() //0 Degree
{
PORTB.F1 = 1;
Delay_us(500);
for(a=0;a<Adcval2;a++)
{
Delay_us(1);
}
PORTB.F1 = 0;
Delay_us(19500);
}
void main()
{
int test1, test2;
TRISA.F2 = 1; //analogue IP servo1
TRISA.F3 = 1; //analogue IP servo2
TRISB = 0; // PORTB as Ouput Port
ADC_init();
do
{
Adcval = ADC_Read(2);
Adcval = map(Adcval, 455, 588, 0, 255);
servoRotate0();
Adcval2 = ADC_Read(3);
Adcval2 = map(Adcval2, 455, 588, 0, 255);
servoRotate1();
}while(1);
}]\code] Mod edit: code tags
Last edited by a moderator: