The problem is that every time I add a slider object and try to connect it to a different servo motor through a different pin the sliders both only control the same servo motor. It won't allow for me to add a servo motor that controls each servo motor independently through the user-interface. I'm using Processing as the interface and Arduino as the IDE.
I have tried adding other slider objects but they all still control the same servo. I do not know if the issue is through Arrduino or Processing. When I add the other sliders, I connect them to their own pins but it still doesn't allow for them to be controlled individually.
Processing code:
import processing.serial.*;
import cc.arduino.*;
import controlP5.*;
ControlP5 controlP5;
Arduino arduino;
int servoAngle = 90;
void setup() {
size(400,400);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
for (int i = 0; i <= 13; i++)
arduino.pinMode(i, Arduino.OUTPUT);
controlP5 = new ControlP5(this);
controlP5.addSlider("servoAngle",0,180,servoAngle,20,10,180,20);
}
void draw() {
arduino.analogWrite(9, servoAngle);
//delay(15);
}
Arduino code:
#include <Servo.h>
#include <Firmata.h>
Servo servos[MAX_SERVOS];
byte servoPinMap[TOTAL_PINS];
byte servoCount = 0;
void analogWriteCallback(byte pin, int value)
{
if (IS_PIN_DIGITAL(pin)) {
servos[servoPinMap[pin]].write(value);
}
}
void systemResetCallback()
{
servoCount = 0;
}
void setup()
{
byte pin;
Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION,
FIRMATA_FIRMWARE_MINOR_VERSION);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.attach(SYSTEM_RESET, systemResetCallback);
Firmata.begin(57600);
systemResetCallback();
// attach servos from first digital pin up to max number of
// servos supported for the board
for (pin = 0; pin < TOTAL_PINS; pin++) {
if (IS_PIN_DIGITAL(pin)) {
if (servoCount < MAX_SERVOS) {
servoPinMap[pin] = servoCount;
servos[servoPinMap[pin]].attach(PIN_TO_DIGITAL(pin));
servoCount++;
}
}
}
}
void loop()
{
while (Firmata.available())
Firmata.processInput();
}
I would like to be able to add 3 more sliders that to the one already created but be able to control 4 servo motors, each controlled by its own slider, but the result I'm getting is that each additional slider is controlling the same motors.