toggle question

wildbill

Member
Hi everyone, using the toggle command on an 18, to flash a LED on and off, is it possible to flash ( or toggle ) the output a set No. of times, e.g. 10 times and then move on to the next command ? I tried the toggle command to flash, but in a loop, I had a look at the command in the manual, but it only gives a loop example. Any ideas ?
wildbill

 
 

Rickharris

Senior Member
isn't a for next loop working for you?

You could set up a variable and count the flashes and jump conditionally when the count reaches a set number (same as the for next actually.)
 

wildbill

Member
Hi Rick, yes, a f/n loop works, but i'm new to 'axes and just playing around at the mo, trying a few things out. I had a brief look at the manual for more detailed explanation, so... what is the toggle command mainly used for ?

 
 

andrewpro

New Member
The toggle command just changes the state of a pin to it's opposite state. If it's a 0, it makes it a 1, and if it's a 1, it makes it a 0.

--Andy P
 

ylp88

Senior Member
You have to do:

if x = y then jump1
resume1:
etc...
jump1:
toggle 6
goto resume1

<b><i>ylp88 </b> </i>
 

andrewpro

New Member
Sadly, no. If Then's can only call a subroutine.

This is not acceptable:

If x=y then toggle 6


This IS acceptable:


If x=y then othersub

othersub:
toggle 6


--Andy P
 

BeanieBots

Moderator
I didn't think an if/then could call a sub and it would have to be written inversely like this:-

If x&lt;&gt;y then NoToggle
Gosub DoToggle
NoToggle:
.
.
.
DoToggle:
Toggle 6
Return
 

andrewpro

New Member
Dang! Didn't realize YLP beat me to it. That's what I get or opening up 9 threads at once.

Beaniebots: I'm not sure what you mean? If your talking about the lack of code between my if..then and label, then that's my mistake, I should have put somehting relating to other code in there. Was jsut trying to show how you cant use commands in the same statement as a then, and it has to call another label.

Otherwise...i'm somewhat confused as to what you mean?

--Andy P

Edited by - andypro on 1/19/2006 5:24:04 PM
 

BeanieBots

Moderator
I mean that I didn't think it was possible to use the address of a gosub after an if statement. That is, the label after an if is jumped to and not gosubed to.

if then label .. jumps to label
if then gosub label is not allowed.
so, if label is a subroutine, where will it return to?
 

evanh

Senior Member
Andy, your use of the word &quot;call&quot; is the confusion. Calling is interpreted as equivalent to GOSUB. Jumping and branching is interpreted as equivalent to GOTO.


Evan
 

wilf_nv

Senior Member
Picaxe basic lacks the following construct

if_then_else_gosub:
IF x=condition
THEN GOSUB response1
ELSE GOSUB response2
RETURN

response1:
......
RETURN

response2:
......
RETURN

for which I use the equivalent construct

if_then_else_gosub:
IF x=condition THEN response1;GOTO response1
....... ;ELSE response2
RETURN

response1:
......
RETURN
 
Top