Hi all
I'm working on my first Arduino-project. It's realy funny, but unfortunately I recently got a problem.
My goal to make a crosshair out of lightsensors. A laser beam aims in the middle of it. When the laserlight exits the middle of the crosshair (-> hit a lightsensor) it should give a signal, that an engine (actually represented by a light) can move the light back to the right place.
I did a screenshot while I was playing around with it in the workroom.
After that I updated my commentaries in the code at home, I hope it's a bit better explained due to them. (on the screenshot are still the old ones, sorry!)
Here are the important parts of the code for now:
#define LEDa 13 // the pin for the LEDa
int photocellPin1 = 1;
int photocell1; // lightintensity from photocell 1
int photocell1old; // old value of the lightintensity
// int dif1; // change of the lightintensity
void setup() {
pinMode(LEDa, OUTPUT);
// Sensors are automatically INPUT
Serial.begin(9600);
}
void loop() {
photocell1 = analogRead(photocellPin1); // read the value from the sensor and save in variable photocell1 - The higher the value of photocell1, the more light shines on the photocell
Serial.print("P1 ="); Serial.print(photocell1); Serial.print(" | Dif1 = "); Serial.println(dif1); // current photocell input
while(photocell1 > 500); // activate reactor (light, engine) as long as the light is shining on the photocell
{
Serial.println("In der while-Schleife!");
digitalWrite(LEDa, HIGH);
photocell1 = analogRead(photocellPin1);
// dif1 = photocell1 - photocell1old;
}
digitalWrite(LEDa, LOW); // stop reactor (light, engine)
delay(1000);
Serial.println();
}
The thing that confuses me is that the program goes in the while-loop, even if 'photocell1' is smaller that the required 500. When it gets bigger than 500 the program just stops and doesen't do anything more.
What's the fault here?