Ok, so I a photocell and laser set up in my Arduino. When the photocell is recieving a signal, a red LED lights up to signify that the laser is on. this is simply set up as a range of values detectable by the photocell. the purpose of this is to count the number of times the photocell has been tripped. More stuff will be added to the circuit later, but im having trouble making the other LED light up like I want it to. I have created a counter that each time the red led turns off the counter becomes +1, but the trouble I am having it where to put the code for the other led to show how many times the system has been tripped. I want the photocell and laser to still looking for breaks but to also be able to continuously count the times it has been broken. Im new to arduino and wasnt sure if the chip can work in this way.
So basically, when the photocell is tripped a counter begins and increases, for each time it is tripped a yellow led will blink for each time and it will continue to look for trips and count trips even when the yellow is blinking.
int photocellPin = 0;// Photocell connected to analog pin 0
int photocellVal = 0; // define photocell variable
int LED1=3;
int LED2=5;
int counter=0;
void setup()
{
Serial.begin(9600);
pinMode(photocellPin, INPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
photocellVal = analogRead(photocellPin);// read the analog from photocell
}
void loop()
{
int current_value;
current_value=analogRead(photocellPin);
Serial.println(current_value); // print to screen
delay(30);
if (current_value<600)
{
digitalWrite(LED1,LOW);
counter=counter+1;
}
else
{
digitalWrite(LED1,HIGH);
}
//THIS IS WHAT IM NOT sure of where to put//
//I want a five second delay between series of blinks that are counting trips and one second between each blink
//ie --- wait 5 sec ---
for(int x=0; x<5000;x++)
{
for(int i = 0; i < counter; i++)
{
digitalWrite(LED2, HIGH);
delay(500);
digitalWrite(LED2, LOW);
delay(500);
}
}
}
any help would be appreciated