First you test the code if the servo is good wired. In loop you set it to a degree value. and test your above code is working. If it does and the servo moves you can continue. Calibrate your servo pulse wide that you reach start and stop position. (no need for X-Sim here, this is your calibration setup and your gauge)
You use the first sample code here:
viewtopic.php?t=1083After this line:
- Code: Select all
//Do here stuff to init display and zero to default
you put all setup part (fitting to your servo as described in the library)
- Code: Select all
myservo.attach(9); //Pin number, (and maybe: min pulse wide, max pulse wide - for calibrate start and stop)
myservo.write(0); // set servo default position
Then you goto:
- Code: Select all
//Do here your LCD or display stuff
And place below there the movement command.
Gear speed and rpm do not have a percent value, so you have to scale it.
Beginning with speed:
- Code: Select all
int maxspeed=200; //Maximum of your skala, you must scale it
int maxservodegree=180;
float devider=float(maxspeed)/float(maxservodegree);
float target=float(speed)/devider;
myservo.write(int(target));
float and int are definitions for with or without a "," number.
You can init a variable like target one time, then you cant write "float target" again. Simple remove the float/int for the second gauge or write "float target2".
myservomovecommend represent the command of your library for executing a move for the servo.
After this you must insert after:
- Code: Select all
//Do here stuff to set display to zero or default
You must insert your movecommand again for the default position (maybe zero).
- Code: Select all
myservo.write(0);
Correct me if there is a math error in scaling to the servo movement.
@vicpopo: do you include such a manual to your post, perhaps with the found servo example?
If a answer is correct or did help you for a solution, please use the solve button.