moad
Newbie level 5
Hi all,
I am trying to control 5 servos using 5 flex sensors. I have succesffuly controlled one servo using 1 flex now when i try to control two m finding it very difficult. can any one suggest any ideas as to why im getting this problem. code runs fine without any errors and the sensors work perfectly (checked the ADC on LCD).
here is my code!
I am trying to control 5 servos using 5 flex sensors. I have succesffuly controlled one servo using 1 flex now when i try to control two m finding it very difficult. can any one suggest any ideas as to why im getting this problem. code runs fine without any errors and the sensors work perfectly (checked the ADC on LCD).
here is my code!
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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); test1 =Adcval; Adcval2 = ADC_Read(3); Adcval2 = map(Adcval2, 455, 588, 0, 255); test2 = Adcval2; if (test1!= Adcval) { servoRotate0(); } else if(test2!= Adcval2){ servoRotate1(); } }while(1); }
Last edited by a moderator: