Ouput high turns off during loop

shon242

New Member
Hi all.

I am trying to write a piece of code that will keep the output high during a loop.

Here is my code.

Code:
do while pinb.6 = 1
		
		high b.3
		sound b.0, (118, 50)	
		pause 50						
		sound b.0, (120, 50)	
		pause 50	; Pause for 0.5ms
		high b.3
	loop
When I run this in the simulation, I can see b.3 goes low when it hits the end of the loop. I checked the manual, but the example code is meant to turn the output(L.E.D) on and then off.


Can someone point me in the direction I need to go?
 
Last edited:

inglewoodpete

Senior Member
Welcome to the PICAXE forum.

Your problem is that, when pinb.6 goes low, execution drops out of the loop. When your code is 'compiled', the compiler inserts an "End" statement at the end of your code. The end statement effectively puts the PICAXE to sleep, disabling practically everything.

Try something like this:
Code:
[color=Blue]Do
   If [/color][color=Purple]pinb.6 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]Then
      [/color][color=Green]'<your code (without the do and loop statements) goes here>
   [/color][color=Blue]Else
      Low b.3
   EndIf
Loop[/color]
 
Last edited:

techElder

Well-known member
Yeah, what IWP said.

Your code is doing exactly what you told it to do.

In other words ...

Keep looping until pinb.6 is not equal to 1. When pinb.6 is not equal to 1, do not loop any more.

You didn't tell the PICAXE what to do after the loop was finished, so the program is done ... END is assumed.
 

lbenson

Senior Member
Note that for posting code, you +almost+ got the format right. If you edit your post to put "/" after the "[" in the trailing "
Code:
", you will get a code block which retains your formatting.

And welcome to the forum.
 
Top