# BasicStampClockInput

#### mpuvdd

Joined Feb 11, 2007
50
Hello all,
I've looked extensively hard into figuring out how to make a BS2 sense a clock signal (1 to 0 or 0 to 1)on one of its I/O pins rather than the pin's individual logic state. I can't figure it out, so could anyone help?
Thanks a lot,
mpuvdd

#### Dave

Joined Nov 17, 2003
6,970
Is this the same question as the one asked here.

If this is a repeat question please let me know and I can lock one of them (tell me which one to lock).

Thanks.

Dave

#### mpuvdd

Joined Feb 11, 2007
50
They are actually different.

#### Dave

Joined Nov 17, 2003
6,970
They are actually different.
No problem I will leave them both active.

Dave

#### beenthere

Joined Apr 20, 2004
15,819
Is there some reason you can't designate the particular pin as an input?

#### mpuvdd

Joined Feb 11, 2007
50
Well, I know how to monitor a I/O pin's state (IN# or by using VAR), I just don't know what kind of code to write in order to make the stamp add 1 to a VAR (Value) when the I/O pins changes states.

#### beenthere

Joined Apr 20, 2004
15,819
In Basic, you can usually INC a register.

Joined Aug 11, 2005
105
(I've never used Basic Stamp so I'm kind of guessing here.)

It sounds like you're trying to detect rising and falling edge on a pin. On some microcontrollers, you can set up an interrupt that automatically calls your function when the level on the pin changes - I have no idea whether this is possible on the Basic Stamp.

To detect if a pin has changed using a simple polling-loop, you can keep a record of its level, and each time round, compare its current level with what it was last time.

psuedocode:
Rich (BB code):
begin loop
if pinvalue != previous then dostuff
previous = pinvalue
dootherstuff
end loop
EDIT: Just thinking that might be a problem if the input changes at the wrong moment.

Rich (BB code):
previous = pinvalue
begin loop
temp = pinvalue
if temp != previous then dostuff
previous = temp
dootherstuff
end loop
However you're doing it, even with interrupts, note that if two changes occur too close together you're going to miss something.