is this too much code ?

wildbill

Member
i'm new to picaxe and programming, and i was trying some simple code below, (LED on/off 10 times, then three quick flashes) is there a shorter way to write the "flash 3" part ?
thanks in advance, wildbill

symbol countup = b0
symbol Rled = 7

main:
pause 1500
for countup = 1 to 10
high Rled
pause 750
low Rled
pause 750
if b0 = 10 then goto flash3

next countup

goto main

flash3:
pause 1000
high Rled
pause 100
low Rled
pause 100
high Rled
pause 100
low Rled
pause 100
high Rled
pause 100
low Rled
pause 100
goto main
end

 

Edited by - wildbill on 1/10/2006 10:24:22 PM
 

ylp88

Senior Member
Because flash3 is mostly repitition, you can use a loop, setup using:

<code><pre><font size=2>
For ...
...
Next ...
</font></pre></code>

Check out the BASIC programming manual to find out how to use this command. I won't
t give you the code here so that you can find out how to do it yourself but, if you still need more help, come back and ask.

To simplify the loop code, cosider using the &quot;toggle&quot; command. Check it out in the BASIC programming manual.

I'm confused as to what<i>if b0 = 10 then goto flash3 </i> does. The For-Next loop will quit after the variable b0 get to 10, as specified in the <i>for b0 = 1 to 10&quot; </i> . Also, as soon as the &quot;main&quot; routine finishes, the &quot;flash3&quot; routine starts and this routine contains the &quot;end&quot; command. Therefore, the <i>goto main </i> command line is never executed.

EDIT: Just realised that you used the For-Next command in your &quot;main&quot; routine, so this should be no problem for you. Come back and ask if you still need help, though...

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

Edited by - ylp88 on 1/11/2006 12:29:04 AM
 

lsallen

New Member
if you change flash3 to the code below then it should work just as well but in less code.

flash3:
pause 1000
For b1 = 0 to 2 'Loop 3 times
pause 100
low Rled
pause 100
Next b1
goto main
end


L S Allen

Edited by - lsallen on 1/11/2006 9:05:02 AM

Edited by - lsallen on 1/11/2006 9:06:00 AM
 

ylp88

Senior Member
That won't quite work, lsallen.

You'll need something a bit extra:<code><pre><font size=2>
flash3:
pause 1000
For b1 = 0 to 2 'Loop 3 times
<b>high Rled </b> ' &lt; &lt; &lt; &lt; &lt; &lt; &lt; &lt; &lt; &lt;
pause 100
low Rled
pause 100
Next b1
</font></pre></code> Without it, the LED would never come on during the loop.

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

Edited by - ylp88 on 1/11/2006 11:50:29 AM
 

andrewpro

New Member
Since your only pausing for ~100 ms for each repetition, you could cut it down further by using pulsout 10000, rather than highs and lows.

--Andy P
 
Top