View Single Post
  #3   Spotlight this post!  
Unread 03-02-2006, 18:08
RIgnazio RIgnazio is offline
Registered User
no team
Team Role: Webmaster
 
Join Date: Jan 2005
Rookie Year: 2004
Location: .
Posts: 45
RIgnazio will become famous soon enough
Re: Beginning programmer: Variable question HELP!!!

Quote:
Originally Posted by Calvin
OK i'm going to be setting by my computer refreshing every 30 seconds checking for reply

In file user_routines.c, under

/***DEFINE USER VARIBLES AND INITIALIZE THEM HERE ***/
I added:
static unsigned int bob = 2;

------------------------------------------------------------
------------------------------------------------------------
Now under the:
Void Default_Routine(void)
{
if(bob == 2 && p1_sw_trig){bob = 0;}
if(bob == 0 && p1_sw_trig){bob = 1;}
if(bob == 1 && p1_sw_trig){bob = 0;}

}

------------------------------------------------------------
------------------------------------------------------------
Before I click on the trigger, I get the value 2 for bob...
Click on it once, I get 0
click on it again I get 0(it's suppose to change to 1)

WHAT AM I DOING WRONG!?!!?
Please help!
Try this:
Quote:
Void Default_Routine(void)
{
static unsigned int trigger_count = 0;

if(p1_sw_trig)
{
++trigger_count; //sets a trigger counter to control the value
}
else
{
}
if(trigger_count > 1) //Change as needed
{
trigger_count = 0; //Resets trigger count
}
else
{
}

if(bob == 2 && p1_sw_trig && trigger_count == 0)
{
bob = 0;
}
else if(bob == 0 && p1_sw_trig && trigger_count == 1)
{
bob = 1;
}
else
{
}

}

Last edited by RIgnazio : 03-02-2006 at 18:11.