light sensor

i need some help on a school project and was wondering if some one can help. i need to make 2 light sensors to have them control 2 leds so that if i were to cover one of the leds the led should flash slower and if i put a light on the led the light should flash for for a longer time

//light sensor proget

int ledPin = 6;

int ldrPin = 0;

int lightVal = 0;

int ledPin1= 7;

int ldrPin1 = 1;

int lightVal1 = 1;

void setup()
{

pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
}

void loop()
{

lightVal = analogRead(ldrPin);

digitalWrite(ledPin, HIGH);

delay(lightVal);

digitalWrite(ledPin, LOW);

delay(lightVal);

lightVal1 = analogRead(ldrPin);

digitalWrite(ledPin, HIGH);

delay(lightVal1);

digitalWrite(ledPin1, LOW);

delay(lightVal1);
}

Look at the blink without delay example.

The blink without delay example is what you should look at and make 2 of them running together.

Your problem is/will be that the the delay() function stops the program at that point (should be called stop() :)) and so will not allow you to smoothly control 2 lights at the same time. You need to implement a scheme that does not just stop the program - the example shows you how to do this with the millis() function and a few variables.

Good luck!

unsigned long time = o; 
delay = 0; // the delay time
boolean led1 = FALSE; //status of led 1
int ledPin = 6;
int ldrPin = 0;

loop{
delay= analogRead(ldrPin);
if (time+delay < millis()){
  if(led1 == FALSE) digitalWrite(ledPin, HIGH); // this toggels the led, there probably is a neater way to do it but i couldnt think of it
  else digitalWrite(ledPin, LOW);
led1 != led1; // toggel the status of the led
time = millis(); // reset your timer starting point so that the next calculation
}
}

the above isn't very neat but i think it is about what you need if you correct it,
also in your original code

       lightVal1 = analogRead(ldrPin);    
       digitalWrite(ledPin, HIGH);

dont make sense. i think you wanted the variables "ldrpin1" and "ledpin1" there.

anyway as suggested look at the timer blink example (called blink without delay i think) and you wil be good to go

one last tip: try to neatly organize your variables
the same things below eachother and in the same style
dont start counting at nothing an then jump to 1 like you did but rather start at zero then and use underscores for extra points.

int led_Pin_0 = 6;
int led_Pin_1= 7;

int ldr_Pin_0 = 0;
int ldr_Pin_1 = 1;

int lightVal_0 = 0;
int lightVal_1 = 1;

Moderator edit: Code tags added, italics tags removed.

and use underscores for extra points.

Better still, use tags when posting code

and use underscores for extra points.

Why? CamelCase, or camelBack, is perfectly acceptable.

excuse me for not using [code ] [/code ]
but obviously the underscore thingy was just a joke, i am well aware that you don't get extra points for that . . .
however my advice still remains the same when using numbers in a variable title.
sepparate them with a underscore form the main title.
this chitchat however does not help pavel so i will not further polute this topic with none helpfull information besides this message.

Pavel, could you give us an update if you fixed youre program or still have questions/issues