I have a potentiometer -- let's call it a volume knob -- that goes from 0 ohms to 10k ohms. I'm trying to come up with a good way to detect when the volume is turned up quickly. No matter where it is in its range, I'm trying to detect anytime it goes up by say 10% or more within a say 50ms. It needs to continually monitor for quick changes -- no start or stop timeframes or high/low limits to work with -- it needs to detect fast change of 10% anytime it happens within 50ms, wherever it is in the range and whenever it happens. I can't come up with a good approach that doesn't require keeping a running log of readings, which seems a bit brute-forcey... Any ideas?
ArduinoTom:
no start or stop timeframes or high/low limits to work with
Hi, what does that part mean?
Why not just take a reading every 50ms and compare each new reading to the last reading?
What if the analog reading is 10 or under? Any change will be at least 10%.
Paul
50 millisecs isn't fast as far as the Arduino is concerned.
Use the technque in the Blink Without Delay example sketch to use millis() to time things so you take a reading every 50msecs. Save the value in a variable. Have another variable that holds the previous reading. Compare the new with the old. Replace the old with the new. Repeat as needed.
...R
You should probably be thinking in terms of absolute rate of change (volts per second or whatever) rather than rate of percentage change. In other words, think of the "10%" or whatever as being 10% of the full scale value, not of the current value.
Thanks for the replies. Let me clarify the 10%. The circuit creates a 0 to 5v signal that varies over time -- sometimes slowly and sometimes quickly. By 10%, I meant anytime it goes up by more than .5 volts within 50ms. I'll need to do a little trial and error to pick those values in reality (so maybe .4v within 85ms, or whatever) jut that's the idea.
When I said no timeframe or high/low limits, I just meant there was no particular time to start the stop watch, nor any place within the 0-5v range when it reaches a trigger point.
I was hoping to avoid storing a log of values and comparing each new one to the lowest within the last 50ms, but that's the only thing I've come up with so far too...
I don't see any need to record multiple measurements. Can't you just record the new measurement against the previous measurement at regular intervals, calculate the implied rate-of-change and act accordingly?