#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
Servo myservo3; // create servo object to control a servo
Servo myservo4; // create servo object to control a servo
int potval1; // variable to read the value from the analog pin
int potval2;
int potval3;
int potval4;
void setup() {
Serial.begin(38400);
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
myservo3.attach(5);
myservo2.attach(6);
}
void loop() {
potval1 = map(analogRead(0), 0, 1023, 0, 180); // reads the value of the potentiometer (value between 0 and 1023)
potval2 = map(analogRead(1), 0, 1023, 0, 180);
potval3 = map(analogRead(2), 0, 1023, 0, 180);
potval4 = map(analogRead(4), 0, 1023, 0, 180);
myservo1.write(potval1); // sets the servo position according to the scaled value
Serial.print("X");
Serial.println(potval1);
myservo2.write(potval2);
Serial.print("Y");
Serial.println(potval2);
myservo3.write(potval3);
Serial.print("Z");
Serial.println(potval3);
myservo4.write(potval4);
Serial.print("V");
Serial.println(potval4);
delay(10); // waits for the servo to get there
}
I’m only getting one line of values with all of them meddled with each other and would like to see all of them separately.
There is a way to combine all these into a neat one liner but uses sprintf or something and the syntax is complex. The code above will produce tabbed results, works well for my FFT code when I'm trying to view multiple bins.