' {$STAMP BS2} ' {$PBASIC 2.5} 'Hello all, 'I am using a basic stamp 2 with pbasic 2.5. 'I need TO figure out a way TO essentlaly say when a certain INPUT ' of pulses reaches a certain number it will turn a certain PIN HIGH. ' AFter a short Delay that PIN will go back LOW. 'The program still needs TO COUNT pulses even WHILE bringing pins HIGH AND LOW. 'THen it needs TO DO the whole thing over again. ' A basic idea I had was IF there was a "when" command ' I could just say when pulsein = 45 OR so bring PIN 1 HIGH. ' Anybody think that might work. 'Has anybody got any better ideas? 'Thanks in Advance! ' *** I/O Definitions *** LEDPin CON 1 PulsePin CON 2 Time VAR Word ' Gets the value of the pulse width TimeLimit CON 45 ' 45 * 2 uS == 90 uSec pulse width limit LEDLimit CON 50 ' 50 * 20 mSec per loop is 100 mSec LED 'blink' LEDState VAR Bit ' 0 == off, 1 == on LEDTime VAR Byte ' Count time LED's been on. ' ********** Initialization ******** SEROUT 16, 16486, ["Reset", 13] Time = 0 LEDState = 0 ' zero is 'off' state LEDTime = 0 ' Number of 'ticks' we've beein in LEDState GOSUB SetLED ' ********** Main Routine ****************** MAIN: LEDTime = LEDTime + 1 PULSIN PulsePin, 1, Time 'counts pulses from the optoisolater and stores it in var time IF Time < TimeLimit THEN 'measures the counted pulses, change in accordance with the opto disk used LEDState = 1 LEDTime = 0 GOSUB SetLED ENDIF IF LEDTime > LEDLimit THEN LEDState = 0 GOSUB SetLED ENDIF GOTO MAIN ' ********* Subroutines ****************** SetLED: IF LEDState = 0 THEN HIGH LEDPin ' Active low, 'HIGH' turns it off ELSE LOW LEDPin ENDIF RETURN ' Problems: ' 1. It looks like you're measuring the LENGTH of the input pulses, ' not counting the NUMBER of input pulses, so that's what this ' program continues to do. It will need modification if you ' REALLY want to COUNT pulses, as your comments indicate, ' instead of MEASURING pulses, as your code showed.