This may appear to be a strange question, but how can i detect switching on the leading or trailing edge of a switch only. I want to be able to count the number of times a switch or contact is operated.