Adaptive Threshold With Arduino Input
Hey All,
So I've made this little patch tidbit, but I'm wondering whether there's a better way of approaching it as I find it finicky and not always as responsive as I would like. What I essentially did was modify the Sensor Tamer patch.
What I'm Trying to Do:
We're using this sensor to measure breath (http://moderndevice.com/product/wind-sensor/), hooked up via Arduino and Benson's Sensor Box, We're using it to trigger audio and video, and this is going to be sitting in a gallery for three months so I want it to work in as work well and for a public who will approach try to make it not work (that's what I do at least whenever I enter interactive art things). We picked this sensor because it is good at picking up general gusts of breathing whereas some pressure sensors needed a very specific spot in order to get proper values. The sensor will ultimately be contained in a box with a slight funnel to focus the exhalation on it.
My Problem:
So how the sensor works is it heats up when someone breaths in and then cools down. So the tricky thing about this is lets say someone breaths in it rapidly, it stays hot due to the cool down time, so setting absolute thresholds (i.e., raise up to 67% of values, dip to 33% before registering as an "event") isn't gonna cut it because it can take time for the sensor to dip back down to 0% and simply won't if someone breaths rapidly into it.
My Solution:
In pseudocode this patch essentially (attempts to) compare current state to where the value was, if you are greater than and then drop down to 95% of the previous value, then trigger an event. I'm wondering whether any of you brilliant folks have ideas for a better approach?
My Max Fu (well with some stolen bits from the giants) is attached as a file. I annoyingly can't paste code lately.