# take a logarithmic curve and make it linear?

Hey all!

i am taking a raw square wave signal from a synthesizer and trying to convert that into brightness for an LED.

Unfortunately, since frequency doubles every octave, I am not getting a linear response for the dimmer. Weirdly, it is the opposite of what I would expect.

Between the lowest note and the same note an octave up, the light goes from off to half bright. and it gets brighter slower and slower as I ascend.

Does this make any sense? This seems like it should be easy to do, but I dont really know where to go from here…

Thank you!!

its kinda like i wanna draw a line between the lowest and the highest points and have the arduino follow that somehow...

i am taking a raw square wave signal from a synthesizer and trying to convert that into brightness for an LED.

How?

You need to post some code or have a much better description of what you are doing.

What is it about the square wave that you are converting into brightness?
Is it the frequency?

Sorry, I was very tired when I wrote that post. So I am actually mapping the pitch of the synth to the hue of the LED.

I am getting the sqr wave out of the synth directly. There is a solder point on the circuit board that is just a square wave out.
I have that going directly into digital pin 7, and ground of the synth is wired into arduino ground.

``````#include <HSBColor.h>

#define REDPIN 9
#define GREENPIN 10
#define BLUEPIN 11

int squarewave = 7;     //sqr input from volca
unsigned long duration;  //duration of wavelength
int huemap ;             //mapped hue that sqr input
int colors[3];            //color array

void setup()
{
pinMode(squarewave, INPUT);
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
Serial.begin(9600);
}

void loop(){
duration = pulseIn(squarewave, HIGH);
huemap = map(duration, 200, 17000, 0, 255);
H2R_HSBtoRGB(huemap, 99, 99, colors);
analogWrite(REDPIN, colors[0]);
analogWrite(BLUEPIN, colors[1]);
analogWrite(GREENPIN, colors[2]);
}

}
``````

Human senses like pitch, loudness and brightness are all approximately logarithmic in response -- so 10 times as much noise power sounds "twice as loud". The same is true for LED brightness, that is "twice as bright" is about 10 times as much light. You can correct for this by using an exponential lookup table to program brightness. Here is an example, but Google will provide many more logarithmic LED brightness function | AVR Freaks

might be a job for - http://playground.arduino.cc/Main/MultiMap -