Yep, you're right. I didn't think to include a "the press is from the last time through!" check. Your code should work, but just for the sake of completeness...

(new stuff in bold)
Somewhere at top of file:
Code:
// Your stuff
#define T_DRIVE pwm01
#define Up_T_Limit rc_dig_in01 /* Limit Switch on Full Up Set */
#define Down_T_Limit rc_dig_in02 /* Limit Switch on Full Down Set */
#define T_BUTTON_BTN p2_sw_trig /* Button to change T state. */
int intTState = 0; /* T state variable. */
// My stuff
#define RC_SWITCH_ON 0
#define RC_SWITCH_OFF !SWITCH_ON
#define OI_SWITCH_ON 1
#define OI_SWITCH_OFF !OI_SWITCH_ON
#define T_STATE_UP 1
#define T_STATE_DOWN !T_STATE_UP
int buttonPressedLastTime = 0;
Somewhere in main loop:
Code:
if(T_BUTTON_BTN == OI_SWITCH_ON)
{
// Switch states only if this button press isn't from a loop before
// (the user held it down).
if(buttonPressedLastTime == 0)
{
if(intTState == T_STATE_UP)
{
intTState = T_STATE_DOWN;
}
else
{
intTState = T_STATE_UP;
}
}
buttonPressedLastTime = 1;
}
else
{
buttonPressedLastTime = 0;
}
if(intTState == T_STATE_UP && Up_T_Limit == RC_SWITCH_OFF)
{
// We need to go up more
T_DRIVE = 255;
}
else if(intTState == T_STATE_DOWN && Down_T_limit == RC_SWITCH_OFF)
{
// We need to go down more
T_DRIVE = 0;
}
else
{
// We are at our goal. Stop motor
T_DRIVE = 127;
}
I'm pretty sure that works... hasn't been compiled, but hey, I'm perfect.
