Picaxe Debug

Hello LMR,

I mean this posts for thos who know something about Picaxe:

I need help! Please someone go over the code and tell what did I do wrong so that when I make pin 4 = 1 nothing happens!

Did I miss anything, did I add something that is wrong?  Don´t worry about the spanish parts they are just labels.

 

init: pause 500
serout 7, n2400, (254,1)

main:

if pin3 = 1 then puerta2

if pin3 = 0 then ledoff

if pin4 = 1 then puerta3

if pin4 = 0 then ledoff


puerta2: `Puerta de la terraza

high 2
serout 7, n2400, (254,128, "----¡Alerta!----")
serout 7, n2400, (254,192, "¡TerrazaGrande!")

pause 100

if pin1 = 1 then alarmreset

if pin1 = 0 then puerta2


puerta3: `Puerta que dá al lavadero y al cuarto del 2ndo piso

high 2
serout 7, n2400, (254,128, "----¡Alerta!----")
serout 7, n2400, (254, 192, "Puerta lavadero!")

pause 100

if pin1 = 1 then alarmreset

if pin1 = 0 then puerta3

ledoff: `Si todos los circuitos estan abiertos, todo bien

low 2

serout 7, n2400, (254,128,"---Todo Bien!---")

pause 100

goto main


alarmreset: `Para resetear la alarma y que deje de sonar (circuito tiene que estar abierto otra vez)

low 2

serout 7, n2400, (254,1)
pause 30

serout 7, n2400, ("---RESETEADO!---")
pause 3000

serout 7, n2400, (254,1)
pause 30

goto main

A lot of issues.

There is a lot here.

There is nothing at the end of any of your routines. Start at the beginning:

main:

if pin3 = 1 then puerta2

if pin3 = 0 then ledoff

if pin4 = 1 then puerta3

if pin4 = 0 then ledoff

*** right here!!*** After doing the 4 lines above, it just keeps going! you need a goto main here


puerta2: `Puerta de la terraza

 

Same problem with the other routines. Are they routines or subroutines? Goto’s or gosub’s? Go through the code with the simulator or by hand and you should see what is going on.

 

noticed more

You are never going to get past the 2nd line after main. The first 2 IF’s. Pin 3 is always going to be either 1 or 0 so you are always going to go to either puerta2 or ledoff. The code above will never get to IF PIN4…

Okay so:

So I am missing an ending for the rutines right?

From what I understand I need to do the following:

if pin3 = 1 then puerta2

if pin3 = 0 then ledoff

if pin4 = 1 then puerta3

if pin4 = 0 then ledoff

goto main  <<<<<<<<  I need this right?

But this isnt the end of the code, so if I am right the goto main should be at the end of main?

Thanks…

 

edit they are supossed to be subrutines, I checked it and it never checks the rest of pins, but why?

You really need to read the manual !

If you jump back to main from the subroutines you never get to execute the statement after the routine has been called


If pin3 = 0 then gosub LedON
… next statement

LedON:
    High LED
    Return

Okay okay

okay so let me see if I get it:

If I use goto main, the next statement wont be executed so what I need to do is

if pin3 = 0 then gosub LedON

if pin4 = 0 then gosub LedON

LedON:

high 2

return <<<<instead of goto main

Okay now its right

I followed your advice, took goto ledoff command used return and now… IT ALL WORKS! thank you again Geir Andersen!