Sorry this might be a long post but I'm stumped as to the answer.
This code will not run if you dont have a PCA 9685 pwm servo driver unless of course you can understand whats going on or can bypass the driver bits.
If you cant guess from the code its to move gauges for a flight sumulator (flightgear) a sample bit of code it supplied in the doserial function.
Curently I have only one servo connected (servo 14) with a 1:2 ratio to rotate the needle, as it is the easiest to show movement without actually having to fly the sim.
If you run the supplied code you will see from the terminal screen that the captured data is as supplied yet the mapped data is minus 2 for all data inputs via the setservopos function.
The data passed from the doserial function, is as expected, as is the data from the print statements, yet the servo will not respond to the mapped results. The last data item 1500 data should put the RPM gauge to approx mid range but it goes to full scale,
Input the servo min or servo max figures and the servo will move to those positions. I am assuming the problem lies within the setservopos function as servo is not responding to the code as expected. If you change servo 14 data (the last data item in the string) to 250 the gauge will read 0, change to 635 the gauge will read 3500.
I actually calculated the map function and it calculates out as expected. I included the calcs as maths is like Shakespeare to me (gibberish).
servo min 250 servo max 635 fsmin 0 fsmax 3500
(x-inmin) * (outmax -outmin)/(inmax-inmin)+outmin
for the range it is
0-0 * (635-250)/3500-0) +250
0 * 385 /3500 +250
0 * 0.11 + 250
0 + 250
= 250 servo min.
3500-0 * (635-250) /(3500-0) +250
3500 * 385 /3500 +250
3500 * 0.11 +250
385 + 250
= 635 servo max.
So where have I gone wrong?
parsein_tc182.ino (11.8 KB)