Hi,
I am working on a mini robot project where i am trying to drive servos using the PS2 controller. I have defined the different servo positions as an array as shown below:
const uint16_t servo_clockwise[17] = {150, 178, 206, 235, 263, 291, 319, 347, 375, 404, 431, 460, 488, 516, 544, 572, 600};
These servo positions allow me to rotate the servo from 0 degrees up till 180 degrees. I check if the right joystick up position is pressed and then start rotating the servo. In the for loop i have an if condition to check if the right joystick has been released to its neutral position and if it has, then i break out of the loop as shown in the code below:
uint8_t m; if(ps2.ry == 0x00) { //if right Joystick pressed up for(m = 0; m < 17; m++) { OCR1A = servo_clockwise[m]; delay1s(); if(ps2.ry != 0x00) { break; } } OCR1A = servo_clockwise[m]; }
But the break statement doesn't take me out of the loop, and the servo continues rotating till it completes 180 degrees. Not able to figure out why the break doesn't exit the for loop. Need help with this.
Thanks,
Sumair