Shop OBEX P1 Docs P2 Docs Learn Events
- Input is reading erratically. — Parallax Forums

- Input is reading erratically.

MrdavidjenkinsMrdavidjenkins Posts: 49
edited 2005-10-09 02:32 in BASIC Stamp
Good Evening,
I am trying to count the number of time a light sensor gets interupted using a mechanical relay and some simple code.· Here is the code:

ReadLight:
· IF IN5 = 1 THEN
······· do
······· loop until IN5 = 0
······· mycount = mycount + 1
· ELSE
· ENDIF
· DEBUG ? mycount
·' This is where I think I should have a pause or
·' Somehow reset the input.
RETURN


The logic is that this routine gets called from a do-loop.· I want to read the input on IN5.·When IN5 goes to 1, I know that the·beam was interupted, but need to wait until it has fully passed.· ·When the IN5 goes to 0, I know that the object has passed and I should count it in the mycount.·

But what is get is extra counts.· I will interupt the beam 10 times and get a reading of 12, for example.· It is erratic, sometimes interupting the beam 10 times will give 13 readings, sometimes 10.

I have played with putting pause statements below the debug statement - from pause 10 to pause 1000.· Not successful.

The length of cord between the relay and the basic 2sx stamp is about· 4ft.· The relay sounds pretty positive.·

Again, your help is very appreciated
Sign In or Register to comment.