Well, it depends on how your robot is designed, and what your program already has in it.
The button pushing part is easy, just look in dashboard to find the button you want. Something like the following will toggle up/down on press. You don't need to hold the button with this routine either:
Code:
//at the top:
#define BUTTON p3_sw_trig
//in the loop:
static char armMove;
if(BUTTON & armMove==0){
if(the arm is down)
armMove = 1;
else
armMove = 2;
}
if(armMove){//this uses the fact that both 1 and 2 will be true, while 0 will be false.
if(moveArm(armMove))
armMove = 0;
}
then, down the page (or in another file), you need to have a function that actually moves the arm, and returns true if the arm is done moving.
Code:
int moveArm(char way){
char finished
if(way == 1){
//move the arm up, set pwms.
//you probably want to use a PID loop.
//return 1 if the arm is there already, and set the pwm to 127.
} else {
//move the arm down, set pwms.
//you probably want to use a PID loop.
//return 1 if the arm is there already, and set the pwm to 127.
}
return 0;
Thats the way I would attempt to do it. Depending on your bot, you may have to use some sort of a PID loop to get the arm to the correct position. If you use limit switches instead of a POT, you could probably do it with just a P loop.