For...Next?

Axel87

Senior Member
Code:
; ****************************************************************************************************
; _______ _________ _        _______  _______   _______           _______  _______  ______  
;(       )\__   __/( (    /|(  ___  )(  ____ ) (  ____ \|\     /|(  ___  )(  ____ )(  __  \ 
;| () () |   ) (   |  \  ( || (   ) || (    )| | (    \/| )   ( || (   ) || (    )|| (  \  )
;| || || |   | |   |   \ | || |   | || (____)| | |      | (___) || |   | || (____)|| |   ) |
;| |(_)| |   | |   | (\ \) || |   | ||     __) | |      |  ___  || |   | ||     __)| |   | |
;| |   | |   | |   | | \   || |   | || (\ (    | |      | (   ) || |   | || (\ (   | |   ) |
;| )   ( |___) (___| )  \  || (___) || ) \ \__ | (____/\| )   ( || (___) || ) \ \__| (__/  )
;|/     \|\_______/|/    )_)(_______)|/   \__/ (_______/|/     \|(_______)|/   \__/(______/ 
;                                                                                                      		                          
; ****************************************************************************************************
;    Filename: 		
;    Date: 			
;    Target PICAXE:
; ****************************************************************************************************
;
;
	symbol counter=b1	
	symbol led=b.4
	symbol buzzer=b.2		
main:
	for counter = 1 to 5
		high led
		high buzzer
		pause 500
		Low  led
		Low buzzer
		pause 500
	next counter 
main1:	
	for counter =1 to 2
	goto main
	next counter
	end
Trying to alter code that I got from the manual.
What I am trying to accomplish is have "main" repeated 5 times..wait...repeat 2 more times.
Am I overthinking this?
Let me know if these questions belong in a different forum
And thanks for any help!
 

bpowell

Senior Member
In your "Main1" code, you start the for-next loop, but then you "goto main" which jumps the program OUT of your for-next loop before it can ever progress...

In main1, "counter" is set to 1...then "goto main" hits, and main then resets counter to 1, and starts the 1 - 5 for-next loop.

You could look at putting your beep / flash routine into it's own subroutine...then having a variable such as "loops" that you set to the number of loops you want, and then call it with a gosub.

Code:
main:
loops = 5
gosub flash
pause 500
loops = 2
gosub flash
pause 200
goto main

flash:
for counter = 1 to loops
high led
high buzzer
pause 500
low led
low buzzer
pause 500
next counter
return
 

westaust55

Moderator
One option to consider:
Code:
	symbol counter=b1	
	symbol led=b.4
	symbol buzzer=b.2		
main:
	for counter = 1 to 5
	    GOSUB LEDnBuzzer	
	next counter 
	PAUSE 9999 ; your desired pause here
	for counter =1 to 2
	    GOSUB LEDnBuzzer	
	next counter
	end

LEDnBuzzer:
	high led
	high buzzer
	pause 500
	Low  led
	Low buzzer
	pause 500
	RETURN

EDIT:
And bpowell got in there with another alternative before me ;)
 
Top