Shop OBEX P1 Docs P2 Docs Learn Events
Pure Newbie — Parallax Forums

Pure Newbie

Jonathan AllisonJonathan Allison Posts: 96
edited 2005-02-08 04:42 in BASIC Stamp
Yes, I admitt it! I am newbie to bs2 hehe

' {$STAMP BS2}
' {$PBASIC 2.5}

lngCount VAR Word
lngGreen VAR Word
lngRed VAR Word
lngDelay VAR Word

lngGreen = 1
lngRed = 1
lngDelay = 1500

FOR lngCount = 0 TO 10000
PAUSE lngDelay

DEBUG "Green: ", DEC lngGreen, CR
DEBUG "Red: ", DEC lngRed, CR

IF lngGreen = 1 THEN
GOTO GreenOff
ENDIF

IF lngRed = 1 THEN
GOTO RedOff
ENDIF

lngGreen = lngGreen + 1
lngRed = lngRed + 1

IF lngRed > 10 THEN
GOTO RedOn
lngRed = 1
ENDIF

IF lngGreen > 15 THEN
GOTO GreenOn
lngGreen = 1
ENDIF



NEXT

GreenOn:
HIGH 14
RETURN
GreenOff:
LOW 14
RETURN
RedOn:
HIGH 15
RETURN
RedOff:
LOW 15
RETURN

this code makes it so lngRed and lngGreen are always 1. Can't figure out for the life of me why this would be? I am, however, use to programming in php, c, c++ and other oop languages.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Johnny

Comments

  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-08 04:20
    Johny,

    A couple of things.

    First, I think you are confusing GOTO and GOSUB. GOTO is a branch, where as GOSUB is a subroutine call and has a RETURN to return to where it was called:

    Main:
        If x=1 then
            gosub X1
        else
            gosb notx1
        endif
        goto main
    
    x1:
        debug "x1"
        return
    
    notx1:
        debug "not x1"
        return
    
    



    The second thing is that memory in a stamp is very limited, only 26 bytes. A WORD variable takes 2 bytes. But a quick read of your code indicates that the values of IngRed and IngGree won't exceed 15. In that case you'd be better off using NIB which is a nibble, or half a byte.

    For those of us coming from machines with tons of memory, this bit counting is foreign. But you'll need to get used to it on a stamp.

    Jim
  • Jonathan AllisonJonathan Allison Posts: 96
    edited 2005-02-08 04:42
    sweet, that fixed it (gosub)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Johnny
Sign In or Register to comment.