|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi, i have written a little code that will fire our pistons for approx. 3 seconds when one of the joystick buttons is pushed, so I wrote an if statement after the SERIN that
"if p2_sw_trig = 1 then GOSUB FIRE3" that works and sends it to my sub code which looks like this: FIRE3: relay1_fwd = 1 MyCounter VAR byte StepSize VAR byte MyCounter = 1 FOR MyCounter = 1 TO 3001 STEP StepSize StepSize = delta_t * 25 NEXT relay1_fwd = 0 RETURN but once i push the trigger, i get a basic run error, but, when i take away the FOR...NEXT statements, everything works, what's up with this? can i not do loops inside of subs? thanks a lot Stephen |
|
#2
|
||||
|
||||
|
Re: loops inside of subs???
Quote:
|
|
#3
|
||||||
|
||||||
|
Re: Re: loops inside of subs???
Quote:
|
|
#4
|
|||||
|
|||||
|
Re: Re: loops inside of subs???
Quote:
[edit]As previously stated, MyCounter is a byte which can never reach 3001. As hard as the processor tries, it can never continuously add numbers to a byte and reach 3001. The byte will reach 255 and then drop back to 0 and then repeat which causes an infinite loop. there is no problem with running that loop where you have it. Try using a word (2 bytes stuck together) instead of a byte. If what rbayer says is true then you will never be able to do a loop for that long anyways, but I don't think there is any harm in trying it.[/edit] Last edited by ChrisA : 19-02-2003 at 20:12. |
|
#5
|
|||
|
|||
|
<edit>Removed stuff covered by people who replied faster that me.</edit>
Here is what I suggest. GoSub Fire3: Fire3: count Var word 'Number of 26ms periods Fire3On Var Bit ' 1 if the piston should fire If p2_sw_trig = 1 then Fire3On = 1 If Fire3On = 0 Then DontFire: If count < 3000 then relay1_fwd = 1 count = count + 1 + delta_t Else relay1_fwd = 0 count = 0 Fire3On = 0 EndIf DontFire: Return That is how I would do it, but it may not be exactly what you need. Last edited by redbeard0531 : 19-02-2003 at 20:07. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grease inside the Drill Motor gear box? | archiver | 2000 | 2 | 23-06-2002 23:07 |