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?