![]() |
PBasic Probelm
Hi,
I have 3 push buttons that I am using as a switches. I am using last year's robot controller. What I want to do is when I press a button once, I want it to be like a toggle button. When I press a button, I want the controller to run a sub routine. That is simple, I know, but here is the catch: If while running the sub-routine, a second button is pressed, I want the RC to ignore the second button. When the RC is done executing the subroutine, then I want it to be able to recieve a signal from any other button, but not until it is done executing the first sub routine. Also, I forgot, in PBasic, is this how you used to do sub routines? IF condition THEN gosub FIRST ENDIF FIRST: 'code Is that all there is to it or do I have to declare the sub routine in a different way or end the sub routine in a different way. I'll appreciate any help. |
Re: PBasic Probelm
Quote:
|
Re: PBasic Probelm
You need two subroutines:
One for when the button state is up doing: Set flag to 0 And the other when the button state is down doing: Set flag to 1 (other stuff) This way, the flag will be 1 if the button is pressed down. Then at the top of the other button's code, put an if flag = 0 then, so that code will not execute unless the button is up. |
Re: PBasic Probelm
Do something like this: (this is in pseudo-code)
Code:
global variable FirstActivated initialized to 0 |
Re: PBasic Probelm
Quote:
|
Re: PBasic Probelm
Quote:
|
Re: PBasic Probelm
Quote:
FIRST is a label. Wouldn't you use goto, not gosub? I know that in Visual Basic (similar so far), you define a sub as: Code:
Public Sub foo () |
Re: PBasic Probelm
Quote:
Code:
MainLoop: |
Re: PBasic Probelm
1 routine. 'gosub' instead of 'goto'. 'return' to go to the most recent gosub. 'stop' to halt everything. Got it.
|
Re: PBasic Problem
I would do something like this:
Code:
None con 0[edit] Note 1: As Joe mentioned, more than one button could be pressed at the same time. The way I've coded it, button 3 would have the highest priority, and button 1 the lowest (because of the order of the if statements.) Note 2: I didn't indicate how the variable "Done" gets set.... Or even that it's a variable, for that matter. It could be a logical expression like "elapsedProgramCycles > 80" or "proximitySensor = 1". Note 3: Make sure your subroutines return quickly. They should only calculate or set outputs. It won't work to do something like this: Code:
for i = 1 to 80 Code:
' Make sure JJ gets initialized somewhere. (Like when you set the ProgramState variable.) |
| All times are GMT -5. The time now is 02:51. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi