For my EV go kart, I'm trying to have this slide pot (http://www.robotshop.com/grove-slide-potentiometer-2.html) act as a throttle for a pair of Talon speed controllers and Jaguar speed controller (all feeding to motors on the same transmission). And taking bits off of code from the pot's example and code a friend wrote, I'm wondering if this is enough for variable throttle control?
#include <Servo.h>
int throttle = A0; //throttle input pin
int adcIn = 0;
Servo JagTalon; //PWM line feeding Jag and Talon
Servo Talon; // Talon's PWM
void setup() {
// attach controllers:
JagTalon.attach(9);
Talon.attach(10);
}
void loop() {
adcIn = analogRead(adcPin);
JagTalon.writeMicroseconds(adcIn+1000-40);
Talon.writeMicroseconds(adcIn+1000-40);
}
Don't you think you should have at least compiled it before you put it forward for review, and preferably actually tested it?
It looks credible, once you fix the typos, but whether the conversion from the analog input value to the speed controller pulse width is correct, only you can say.
I wouldn't assume that the two speed controllers have identical signal characteristics and they may need to be mapped separately, but if it turns out that you can in fact drive them both with an identical signal then you might as well connect them both to the same PWM output pin and eliminate the other Servo object from your code.