If Pin(DoorUpSW)=0 Then ' if the door switch is pressed (active lo) Pause 25 ' wait for some time If Pin(DoorUpSW)=0 Then ' and check again - if still pressed it must be real and finished bouncing ... rest of code here EndIf EndIf
Const DoorUpSW=1 Dim Integer btnUPctr ' counter to hold the shifts SetPin DoorUpSW,DIN,PULLUP MainLoop: Do ... btnUPctr=btnUPctr<<1 Xor Pin(DoorUpSW) And &h1f ' sample the input pin and shift the bit into the counter ' If this loop is fast, increase the &h1f so we sample more bits... reduce it if the main loop is slower - tune it for your purposes ' If we shift enough zeroes in, the button has been pressed. ' Any bounce (back to 1) will shift a one in and "spoil" our counter for which will start again. Select Case btnUPctr Case 0 : Print"dn",timer Case &h1f : Print"up",timer Case Else : Print"--",timer End Select Loop