Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Light Curtain on: June 18, 2010, 02:20:01 pm
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.
Code:
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
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Light Curtain on: June 18, 2010, 01:36:48 pm
well..if the beam is interrupted, the robot should stop...
3  Forum 2005-2010 (read only) / Syntax & Programs / Light Curtain on: June 18, 2010, 12:55:44 pm
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 :|
Thanks smiley-wink
4  Forum 2005-2010 (read only) / Troubleshooting / Re: Light Curtain on: June 18, 2010, 12:55:03 pm
Might have posted it in the wrong place:|
5  Forum 2005-2010 (read only) / Troubleshooting / Light Curtain on: June 18, 2010, 12:43:06 pm
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 :|
Thanks smiley-wink
Pages: [1]