digital read sensor run servo code help.....

i am making an obstacle detection robot and am using 2 servos and instead of an ultrasonic sensor i am using polu carriers digital distance sensor 10cm, i cant seem to get it working though, all i need it to do is the sensor sees a wall (the sensor is pre programmed all you have to do is hook it up to a battery and it will detect an object 10cm away by flashing an onboard led it does have a trigger pin though) the code i have right now is....

</>

#include <Servo.h>

int if2 = 0;

Servo servo_10;

Servo servo_11;

void setup()
{
pinMode(8, INPUT);
servo_10.attach(10);

servo_11.attach(11);

}

void loop()
{
digitalRead(8);

servo_10.write(3000);
servo_11.write(3000);
delay(10); // Delay a little bit to improve simulation performance
}

There is a lot wrong with that code. It would have helped if you had used [­code] code goes here [/­code] tags round it to stop the forum software interpreting some of it as a smiley. Please edit your post and add the tags. You seem to have tried but you did it wrong

  digitalRead(8);This is an attempt to read the state of pin 8 but you do nothing, such as assigning the value to a variable, with the result

  servo_10.write(3000);
  servo_11.write(3000);

What range of values does the write() function take ?
What do you expect those commands to do ?

here is my new code, instead i am using a switch if it hits the switch it will run backwards and then turn left i havent quite found out how to make it do that but i mostly need help with the else and if statment becuase arduino says its wrong i am using the pro trinket 5v 16mhz usb.

[#include <Servo.h>

Servo servo2;
Servo servo1;
const int switchPin = 4;

void setup()
{
servo1.attach(10);
servo2.attach(11);
pinMode(switchPin, INPUT_PULLUP);

}

void loop()
{
if (digitalRead(switchPin))
servo1.write(3000);
servo2.write(-3000);

else
servo1.write(-3000);
servo2.write(3000);

delay(500);
}]

You're a few braces {} short. If you want to use multiple statements in if/else they must be in {}.

And servo.write() does not take the values you're trying to use. What is it that you imagine write(-3000) will do?

Steve