A virtual State?

Hi,

Im currently working with 2 LDR’s and an LED. Currently the working code allows for when LDR1 is covered, LED is on until LDR2 is covered. then the LED stays off until LDR1 is triggered again.

What I need to add program wise is a WHILE statement, so that “while LED = high” it will blink (got to do the code for that). But the issue is, the blink code will cause the LED to = LOW, knocking out my while statement. I want to create a Virtual high state. It will need to be created several times as ill have several of these setups in the code, so like virtualswitch1-6.

what I was thinking is if possible, when the LED is set to high by the LDR, a virtual high is created, that doesn’t go low until the second LDR is triggered, unlike the LED which will go high and low due to the WHILE statement. This means my WHILE statement will then be “while virtialswitch = high” then the blink code. Is it possible to do this.

int LDR0 = A0; // select the input pin for ldr
int LDR1 = A1; // select the input pin for ldr
int SV0 = 0; // variable to store the value coming from the sensor
int SV1 = 0; // variable to store the value coming from the sensor

///////////////////////////////////////////////////////////////////////////////////////
 void setup() {
 Serial.begin(9600); //sets serial port for communication
 pinMode(13,OUTPUT);
 }
 void loop() {
  SV0 = analogRead(LDR0); // read the value from the sensor
 Serial.println(SV0); //prints the values coming from the sensor on the screen
 if (SV0 < 100)
 {digitalWrite(13,HIGH);
 delay(100);}

 SV1 = analogRead(LDR1); // read the value from the sensor
 Serial.println(SV1); //prints the values coming from the sensor on the screen
 if (SV1 < 100)
 {digitalWrite(13,LOW);
 delay(100);}
 }

I don't understand what you want to do.

What you should do is describe the logic of what you actually want to accomplish, in a way that other people can understand, and then it will be easy to write a program to do that.

jremington:
I don't understand what you want to do.

What you should do is describe the logic of what you actually want to accomplish, in a way that other people can understand, and then it will be easy to write a program to do that.

I think OP means this:

LDR not covered - LED off
LDR covered - LED blink

int LDR0 = A0; // select the input pin for ldr
int LDR1 = A1; // select the input pin for ldr
int SV0 = 0; // variable to store the value coming from the sensor
int SV1 = 0; // variable to store the value coming from the sensor

///////////////////////////////////////////////////////////////////////////////////////
 void setup() {
 Serial.begin(9600); //sets serial port for communication
 pinMode(13,OUTPUT);
 }
 void loop() {
  SV0 = analogRead(LDR0); // read the value from the sensor
 Serial.println(SV0); //prints the values coming from the sensor on the screen
 if (SV0 < 100)
 {digitalWrite(13,HIGH);
 delay(100);}

 SV1 = analogRead(LDR1); // read the value from the sensor
 Serial.println(SV1); //prints the values coming from the sensor on the screen
 if (SV1 < 100)
 {digitalWrite(13,LOW);
 delay(100);}
 }

this is my circuit. LDR0 is on the left, LDR1 is on the right, (Names are used in the code). This is for a train crossing, so when a train crosses over LDR0, it turns the LED on at the crossing. While the LED is on it needs to blink constantly. Once the train has passed the crossing it will reach LDR1, which will turn off the LED.

My issue is, if I use the “while” statement implement it into my code this way “while LED = HIGH {blink code}”. the blink code will cause the LED to go into a low state, knocking out the effect of the “while” as it will no longer be “HIGH”.

What I want to do is where I have “digitalWrite(13,HIGH)” I want a something not physical to go into an on state, ie “(Virtual,HIGH)”, then change the while statement to “while Virtual = HIGH {blink code}” so that when in the blink code an "(LED,LOW) wont knock out the while statement, it will stay on because “Virtual” will stay high until LDR1 is crossed over