Pure Newbie
Jonathan Allison
Posts: 96
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
' {$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
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:
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Johnny