Ir detection question
I'm having a little trouble understanding something...I built the irdetection circuit on pg238, hooked up a single ir detector to a board, and wrote the following code:
counter VAR Byte
irdetect VAR Bit
DO
IF· IN0=0 THEN
FOR counter = 1 TO 5
FREQOUT 8,50,4000
NEXT
ENDIF
LOOP
Works fine, however, when I assign in 0 a variable named irdetect as in the code below, the my irsniffer will not detect ir:
counter VAR Byte
irdetect VAR Bit
DO
IF· irdetect=0 THEN
FOR counter = 1 TO 5
FREQOUT 8,50,4000
NEXT
ENDIF
LOOP
Why is this?
-Rob Morris
counter VAR Byte
irdetect VAR Bit
DO
IF· IN0=0 THEN
FOR counter = 1 TO 5
FREQOUT 8,50,4000
NEXT
ENDIF
LOOP
Works fine, however, when I assign in 0 a variable named irdetect as in the code below, the my irsniffer will not detect ir:
counter VAR Byte
irdetect VAR Bit
DO
IF· irdetect=0 THEN
FOR counter = 1 TO 5
FREQOUT 8,50,4000
NEXT
ENDIF
LOOP
Why is this?
-Rob Morris
Comments
Interesting little problems, its always the small things that seem easy that will give you a hard time.
I took a look through the "Robotics with the Boe Bot" book and on page 226, example problem: TestLeftIrPair.bs2, is a program that is essentially what your trying to do. I took your program and placed the irdetect = IN0 after the DO. I dont really have the strong background with BASIC to tell you why this works but it did for me. Here is the modified program. I also changed the pin.
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Byte
irDetect VAR Bit
DO
'
added here
irDetect = IN2
'
IF (irDetect=0) THEN
FOR counter = 1 TO 5
FREQOUT 8,50,4000
NEXT
ENDIF
LOOP
I hope that helps you, and i give you credit for listening to such a mind numbing tone