Shop OBEX P1 Docs P2 Docs Learn Events
IF statements seem to interfere with pulse reads — Parallax Forums

IF statements seem to interfere with pulse reads

OgborneOgborne Posts: 3
edited 2011-12-15 20:30 in BASIC Stamp
The following program gives different values for the four times when the If statements are enabled. Seem that only the first two tiem are read in this case.

Any ideas anybody?

Using a remote control that is set to control a Sony TV (Not the one supplied by parallax.

' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word (4)
remotecode VAR Byte
index VAR Nib

DO
remotecode=0
DO
RCTIME 9,1,time(0)
LOOP UNTIL time(0) > 1000
PULSIN 9, 0, time(0)
'IF time(0) >600 THEN remotecode.BIT0=1
PULSIN 9, 0, time(1)
'IF time(1) >600 THEN remotecode.BIT1=1
PULSIN 9, 0, time(2)
' IF time(2) >600 THEN remotecode.BIT2=1
PULSIN 9, 0, time(3)
' IF time(3) >600 THEN remotecode.BIT3=1

IF (remotecode < 10) THEN remotecode=remotecode+1
IF (remotecode =10) THEN remotecode=0
FOR index = 0 TO 3

DEBUG CRSRXY, 0, 4 + index , "time(", DEC index, ")",
CRSRXY, 9, 4 + index , DEC time(index)
NEXT
PAUSE 500
LOOP

Comments

  • doggiedocdoggiedoc Posts: 2,240
    edited 2011-12-15 14:49
    Welcome to Parallax Ogborne!

    I was going to add code tags for readability. But I can't edit your post. If you could put [noparse]
    at the the beginning of your code and
    
    at the end[/noparse] for me that will help us read your code.

    Paul

    EDIT: Perhaps if I was a Moderator. :(
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-12-15 15:29
    Ogborne,

    Welcome to the forum!

    Try doing all of your PULSINs before doing any of the IFs. In your current program, the IFs are probably taking enough time to execute that a subsequent PULSIN doesn't get started in time to catch the next pulse.

    Ditto doggiedoc's suggestion regarding your code formatting:

    attachment.php?attachmentid=78421&d=1297987572

    -Phil
  • OgborneOgborne Posts: 3
    edited 2011-12-15 20:22
    Is this better?
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    time VAR Word (4)
     remotecode VAR Byte
     index VAR Nib
    
      DO
    remotecode=0
     DO
     RCTIME 9,1,time(0)
     LOOP  UNTIL time(0) > 1000
    PULSIN 9, 0, time(0)
     'IF time(0) >600 THEN remotecode.BIT0=1
    PULSIN 9, 0, time(1)
       'IF time(1) >600 THEN remotecode.BIT1=1
    PULSIN 9, 0, time(2)
      ' IF time(2) >600 THEN remotecode.BIT2=1
    PULSIN 9, 0, time(3)
      ' IF time(3) >600 THEN remotecode.BIT3=1
    
      IF (remotecode < 10) THEN remotecode=remotecode+1
       IF (remotecode =10) THEN remotecode=0
     FOR index = 0 TO 3
    
      DEBUG CRSRXY, 0, 4 + index , "time(", DEC index, ")",
           CRSRXY,  9, 4 + index , DEC time(index)
            NEXT
                      PAUSE 500
     LOOP
    
    
  • OgborneOgborne Posts: 3
    edited 2011-12-15 20:30
    Thanks - moving the If statements worked! However, the program as writen was based on one from a Basic Stamp tutorial!
Sign In or Register to comment.