def run_on_threshold(callback, mv_lower, mv_upper, mv_reset=10, interval=0.01, repeats=nil)
      AIN::run_on_threshold(callback, @pin, mv_lower, mv_upper, mv_reset, interval, repeats)
    end
def run_on_threshold(callback, mv_lower, mv_upper, mv_reset=10, interval=0.01, repeats=nil)
      AIN::run_on_threshold(callback, @pin, mv_lower, mv_upper, mv_reset, interval, repeats)
    end
Runs a callback after voltage changes beyond a certain threshold.
 This creates a new thread that runs in the background and polls at specified interval.
 When the voltage crosses the specified thresholds the callback is run.

 @param callback A method to call when the change is detected. This method should take 6 arguments: the pin, the previous voltage, the current voltage, the previous state, the current state, and the counter
 @param mv_lower an integer specifying the lower threshold voltage
 @param mv_upper an integer specifying the upper threshold voltage
 @param mv_reset an integer specifying the range in mv required to reset the threshold trigger
 @param interval a number representing the wait time between polling
 @param repeats is optional and specifies the number of times the callback will be run

 @example
   # This polls every 0.01 seconds and will run after a the voltage crosses 400mv or 1200mv.
   # Voltage will have to cross a range by at least 5mv to prevent rapidly triggering events
   callback = lambda { |pin, mv_last, mv, state_last, state, count|
     puts "[#{count}] #{pin} #{state_last} -> #{state}     #{mv_last} -> #{mv}"
   }
   p9_33 = AINPin.new(:P9_33)
   p9_33.run_on_threshold(callback, 400, 1200, 5, 0.01)