Question on sensors integrated into larger program (pir and ultrasonic)

Hey everyone! I'm looking to integrate a couple sensors into a larger program, and then looking for how to duplicate a certain part of the code to achieve the larger end result.

What im ultimately making is a robot, but the part of the code I'm focusing on is the 'head', programmed on its own Uno. I'd like to take two sets of the pir and ultrasonic sensors (one set for left and one for right) and display either a left or right facing bitmap of an eye on an oled screen depending on a person's location relative to the sensors (and as there would be two sets, I would need to duplicate part of the code but somehow make a distinction between each set and change the pins being used accordingly).

And eventually, I would like to set up an i2c communication as an output to a pi, so I can have this trigger motors for pan and tilt for a neck, but I think I can figure this part out myself once I get the main code down. Any help or resources are appreciated. Thanks!

To duplicate/re-use part of code for two different sensors just put it in a function that takes the pin number as input.

QUESTION on code for the PIR motion sensor: What is wrong with this?
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
#include <Servo.h>
Servo servo;

void setup() {
servo.attach (8);
servo.write (0);
delay (100);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT);// declare sensor as input
Serial.begin(9600);
}

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
delay(150);
servo.write(90);
delay (250);
servo.write(0);
delay (250);

if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF

if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}

ERROR MESSAGE:

^
exit status 1
redefinition of 'Servo servo'

Post your code with code tags, to stop smileys from appearing.

Apparently the name servo exists already elsewhere; try another name.

wvmarle:
To duplicate/re-use part of code for two different sensors just put it in a function that takes the pin number as input.

Oh awesome, thanks! I will be putting my code together here tonight or tomorrow and ill try that.