You could try somethink like this:
Code:
program tripleflash3
Dim t As Byte
TRISIO = %00000001
CMCON = 7
Do While 1
Do While Button(GPIO, 0, 1, 0) ' wait for some state...
Loop
If Button(GPIO, 0, 1, 1) Then
TripleFlash()
Do While Button(GPIO, 0, 1, 1) ' wait for some state...
Loop
End If
TripleFlash()
Loop
sub procedure TripleFlash()
Dim t As Byte
For t = 1 To 3
GPIO 0.1 = 1
Delay_ms (100)
GPIO 0.1 = 0
Delay_ms (100)
Next t
End Sub
end.
I don't program in MikroBasic, so the above may need some tweaking to compile.
You'll notice that
* a subroutine is used to replace duplicated code,
* the busy loops e.g.
Code:
label:
if something then goto label
are replaced with
Code:
do while something : Loop
* no more gotos - potentially more readable, and you'll be less likely to write spaghetti code