![]() |
Variable question (solved)
OK i'm going to be sitting by my computer refreshing every 30 seconds checking for reply :ahh:
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! |
Re: Beginning programmer: Variable question HELP!!!
Your problem is that you set bob to 1 and then check to see if it is 1 and the button is pressed and set it back to 0.
Code:
if(bob == 2 && p1_sw_trig)Code:
static unsigned int bob = 2;This is because there is no way that you as a user will be able to tap the trigger for 1 loop (1/42 of a second) and the trigger will actually be pressed for multiple loops. What I think you want to do is keep track of the previous button state and only change states if your current state is pressed and your previous is not. |
Re: Beginning programmer: Variable question HELP!!!
Quote:
Quote:
|
Re: Beginning programmer: Variable question HELP!!!
It takes about 400 to 600 nanoseconds (maybe a bit more) for the three IF statements to execute. You cannot hit the trigger fast enough to satisfy only one IF statement.
The first time through, bob goes from 2 to 0. The next time though, bob goes from 0 to 1 to 0. The code is doing exactly what you told it to do... Regards, Mike |
Re: Beginning programmer: Variable question HELP!!!
wow thanks for the quick reply,
I figured out a way to do it with two buttons. Now it works fine. I completely forgot about the quick loop, and started questioning my programming skills. :D PHP Code:
|
| All times are GMT -5. The time now is 09:08. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi