Back to Parent

The code essentially listens for taps and keeps a running average of the millisecond gap between successive taps. One issue I encountered early on was that during certain procedures the Arduino's single thread was tied up inside of if statements and unable to hear new taps come in; I needed to make sure it was available for listening more often.

I had a sleep procedure that was running every cycle, checking that if the Destresser hadn't heard a tap in a while that it wouldn't just keep running the clock up, since this would skew the timing average very high when tapping resumed. This procedure was important to include, but in order to prevent it from burdening the main loop too much I wrapped it in a two-condition if: 1) counter value is 100, and 2) it's been more than 5 seconds since the last tap was heard. 

The counter would increment by one each loop cycle. Using counter == 100 as the first condition of the if, I incorporated a short-circuit evaluation which would only run the rest of the if statement one out of one hundred loops. This freed up the Arduino to listen to the mic and greatly reduced false negatives in detecting taps.

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!