Math Help!

Hi all after many years of using PIC's I've made the switch to Arduino. I like all the library's and support for different devices. I working on a simple project using a TLC5940 and some leds I want to be able to control the brightness of the leds with a trim pot. I read the analog value with a analog pin but I need to convert the range from 0-1023 to 0-4095 ( that's the PWM value range of the TLC5940)
So I've used this formula in Mikroc before but in Arduino I get a negative answer no where near right

int old_range = 1023;
int new_range = 4095;

val = analogRead(A0);    // read the input pin
                                                             //convert number ranges
                                                             //0ldRange = (OldMax - OldMin)  
                                                            //NewRange = (NewMax - NewMin)  
                                                            //NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin
 ch_fade = (val * new_range) / old_range;

If I use serial.printin to show value of ch_fade its wrong
is there something simple I'm doing wrong?

Try using long instead of int.

I need to convert the range from 0-1023 to 0-4095

Then multiply the analog reading by four.
Better still shift it to the right two places.

look in reference... the word is MAP

knut_ny:
look in reference... the word is MAP

To multiply by 4? I don't think so. And, besides, its map().

map() worked!! thanks alot. I love how easy arduino is I think I was trying that hard way

I think I was trying that hard way

Multiplying by 4 is the hard way? I'm speechless.