Hi, I am trying to use processing to control multiple servos and simultaneously reading analog signal from a sensor. I am trying to use Firmata to do the job as people in other posts did. However, like other people, the ServoFirmata works perfectly to control the servo, but the analog signal was not read. On the contrary, using StandardFrimata let me read the analog signal but the servo respond strangely.
I am not familiar with programming so I directly referenced the processing source code from this post:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294833227
I basically would like to specify pin 2 to 13 as SERVO pins and Analog 0 to 5 as analogRead Pins. Anyone knows how and what I should reference/modify from the Firmata examples to make my own protocol for the described purpose? Thanks.
Here is the processing code I modified from the above post (the arduino is loaded with StandardFirmata):
import processing.serial.;
import cc.arduino.;
Arduino arduino;
int servoPin = 7;
int sensorPin = 0;
float sensorValue = 0;
int pos=0; //servo position in degrees (0..180)
void setup()
{
size(360, 200);
arduino = new Arduino(this, Arduino.list()[1], 57600); //your offset may vary
arduino.pinMode(servoPin,4);
arduino.pinMode(sensorPin,0);
}
void draw()
{
sensorValue = arduino.analogRead(0);
println(sensorValue);
// read mouseX coordinate
int newPos = constrain(mouseX/2,0,180); // update bg & servo position if mouseX changed
if(newPos != pos)
{
background(newPos);
arduino.analogWrite(servoPin, newPos);
println (" newPos = " + newPos );
pos=newPos; //update servo position storage variable
}
}