OZONE Asylum
Forums
OZONE
Need Help With a Logarithmic Function
This page's ID:
31285
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
I have an interesting problem I was hoping some of the math/scripting gurus here could help me out with. I've been building a circuit on top of an Arduino for a project I've been working on. Basically, it's a sophisticated control for controlling a series of lights in programmable patterns (at its simplest, just a series of four lights chasing in sequence). I've got a potentiometer hooked up to it to control the speed of the patterns; using a script I wrote in the Arduino environment, I read the pot, which gives me a value between 0 and 1023, and then I use that to calculate a delay between steps in the pattern. FYI, here?s the basic function that calculates the speed: [code] speedDelayMax = 1200; // Maximum delay in milliseconds float calcSpeedDelay(int potLevel) { speedLevel = speedPotLevel / 1023.0; // Convert the pot reading to a percentage speedDelay = speedLevel * speedDelayMax; // Determine milliseconds of delay return speedDelay; } [/code] Problem is, when using a liner-taper pot, I don't get enough sensitivity toward the fast end. In other words, turning the pot from slow to fast (1023 to 0), the pattern appears to jump very quickly into the fast range. I tried using an audio-taper (or logarithmic-taper) pot and the result is much, much better; the pattern doesn't appear to speed up as quickly toward that end of the turn. The problem at this point, though, is that the taper on the audio pot works the wrong way. I want slow (1023) to be to the left and fast (0) to be to the right, which I can control by connecting the leads to the pot the right way round. Unfortunately, this doesn't change the direction of the taper; that's built into the hardware and can't be changed. So, I've decided to go back to using a linear-taper pot and to use a software solution instead. And that's where I need the help. Basically, what I need is a function that takes the pot reading and recalculates it so that I get a reading that more closely represents the purple line on the following graph: [img]http://sound.westhost.com/pots-f4.gif[/img] The 0 pot reading is the fast end, which is where I need more sensitivity. Luckily, the Arduino environment is close enough to PHP that I've been able to figure it out, but I'm still not very good at the whole math deal. [b]Why not just reverse the leads on the audio pot so it works the opposite way?[/b] Well, as I said, that would reverse the reading I get from the pot, but it wouldn't change the taper. The taper is still at the wrong end. There is such a thing as a reverse-audio-taper (or antilogarithmic) pot, but they are almost impossible to find and would probably be expensive if I could locate one. [b]Why does fast have to be to the right?[/b] It may sound picky, but to me it's intuitive. Turning a volume knob to the right increases the sound. Turning a dimmer knob (which I also have on my project) to the right increases a light's brightness. So, it only makes sense to me that turning the speed knob to the right should increase the speed. [b]Why not ask on the Arduino forum?[/b] If it were an Arduino-specific question, I would. But I have more faith in the people here when it comes to scripting and math. I may not have explained this very well, so let me know if there are any questions. [url=http://www.roadsideresort.com/][img]http://www.wesleytreat.com/events/asylum/sig_wtlogo_events_01.gif[/img][img]http://www.wesleytreat.com/events/asylum/sig_events_01.php[/img][/url] [small](Edited by [url=http://www.ozoneasylum.com/user/169]Wes[/url] on 08-30-2009 02:12)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »