Light Curtain

Hey everybody.
I have an issue with programming an Arduino Mega board.
Here's what I have: a light curtain(made of 2 phototransistors and 2 IR beams) and a 3 Degrees of freedom robot.
I want to condition the movements of the robot to the return of a logic "1" of the light curtain.
My question is...how can I create some sort of a sub-program that will return a 1 or 0 from the light curtain to my main program so that I could use it as a condition further in the program.
I have to mention I am a beginner in programming :expressionless:
Thanks :wink:

I want to condition the movements of the robot to the return of a logic "1" of the light curtain.

You probably need to explain a little more what you are talking about here.

well..if the beam is interrupted, the robot should stop...

What is the conection between the light curtain and the robot?
Wired?
Wireless?
IR?
...?

I am using two laser pointers that point to the phototransistors. The phototransistors are connected to digital pins 50 and 51. I managed to get the phototransistors to work and to send a signal. But I'm intererested on the programming.
I want to create some sort of sub-program that returns a value in the main program.

int sensorPin1 = 50;
int sensorPin2 = 51;
int ledPin = 24;
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue=0;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("start");
}
void loop() {
  sensorValue1 = digitalRead(sensorPin1);
  sensorValue2 = digitalRead(sensorPin2);
  if ( (sensorValue1==0) && (sensorValue2==0))
    sensorValue=1;
  else
    sensorValue=0;
  Serial.println(sensorValue);
  delay(1000);
}

This is the program I managed to come up with. I want to use it as a subroutine that returns a value in order to simplify my main program. How can I do that?

L.E. I am also controlling the robot using the Arduino board

void loop() {
  if ( bothLow ())
    sensorValue=1;
  else
    sensorValue=0;
  Serial.println(sensorValue);
  delay(1000);
}

int bothLow ()
{
  return (digitalRead(sensorPin1) == 0) && 
            (digitalRead(sensorPin2) == 0);
}