Making two servos move to opposite positions with one command

I am new to programming and arduino so please forgive my ignorance in this, my first posting. I have used some code from an arduino project book to connect two servos and control them both from the serial interface.

I am trying to modify the code so that a single command will cause the servos to move in opposite directions (each servo has 180 degrees of range). In other words, if I were to enter L180 the left servo would move to the 180 degree position while the right will do the opposite and move to the 0 degree position . . . L160 would make the left servo go to 160 degrees and the right to 20 degrees and so-on.
Any help with this would be greatly appreciated!

I have pasted the code I am using below.

// Project 26
#include <Servo.h>
char buffer[10];
Servo servo1; // Create a servo object
Servo servo2; // Create a second servo object
void setup()
servo1.attach(5); // Attaches the servo on pin 5 to the servo1 object
servo2.attach(6); // Attaches the servo on pin 6 to the servo2 object
servo1.write(90); // Put servo1 at home position
servo2.write(90); // Put servo2 at home postion
void loop()
if (Serial.available() > 0) { // Check if data has been entered
int index=0;
delay(100); // Let the buffer fill up
int numChar = Serial.available(); // Find the string length

if (numChar>10) {
while (numChar–) {
// Fill the buffer with the string
buffer[index++] =;
splitString(buffer); // Run splitString function
void splitString(char* data) {
Serial.print(“Data entered: “);
char* parameter;
parameter = strtok (data, " ,”); //String to token
while (parameter != NULL) { // If we haven’t reached the end of the string…
setServo(parameter); // …run the setServo function
parameter = strtok (NULL, " ,”);
// Clear the text and serial buffers
for (int x=0; x<9; x++) {
void setServo(char* data) {
if ((data[0] == ‘L’) || (data[0] == ‘l’)) {
int firstVal = strtol(data+1, NULL, 10); // String to long integer
firstVal = constrain(firstVal,0,180); // Constrain values
Serial.print("Servo1 is set to: ");
if ((data[0] == ‘R’) || (data[0] == ‘r’)) {
int secondVal = strtol(data+1, NULL, 10); // String to long integer
secondVal = constrain(secondVal,0,180); // Constrain the values
Serial.print("Servo2 is set to: ");

firstVal = constrain(firstVal,0,180); // Constrain values

#7 below will also help you with your project.,148850.0.html

Thank you both!