user17282: I have a school project, where I'm going to make a traffic light system on a pls. I want to try it out on an Arduino first, just to get the hang of it. 
To make it a little bit more advanced than I have found on the internet, I want to make the lights go in "emergency mode" if the green lights in both directions are on at the same time. It will then go into a yellow blink. 
My idea is something like this: 
// Yellow blinking if fault in the system or operator activates it
int killState = digitalRead(Kill);
int resState = digitalRead(Res);
if (killState == HIGH /*|| greenlights in both directions */) {
 while (resState == LOW;) { // Yellow blink as long as system is not reset
  BLINK();
 }
}

I guess I need a variable or two that tells what state the lights are in, but I'm stuck. Any good solutions out there? 
Another thing is the reset button. I haven't put much effort in it, but I want it to go into the starting point. 
The link to the complete script can be found here.

user13432: For starters, take a close look at this line:
while (resState == LOW;)

That is not the correct syntax. But the real issue is how is this while loop terminated? The value is never set again? 
Cheers!

user10794: You could do something simple to test if both red and green are on,  eg.
if (digitalRead (RED_PIN) == HIGH && digitalRead (GREEN_PIN) == HIGH)
  {
  digitalWrite (RED_PIN, LOW);  // turn off red
  digitalWrite (GREEN_PIN, LOW);  // turn off green
  while (true)
    {
    digitalWrite (YELLOW_PIN, HIGH);
    delay (500);
    digitalWrite (YELLOW_PIN, LOW);
    delay (500);
    }  // end of while
  }  // end of it


If you have other questions please post your code and not a snippet - however I suggest you try to get further on your own. This is obviously an exercise, and the more you try to work it out yourself the more you will learn.

17282: <p>I have a school project, where I'm going to make a traffic light system on a pls. I want to try it out on an Arduino first, just to get the hang of it. </p>

<p>To make it a little bit more advanced than I have found on the internet, I want to make the lights go in "emergency mode" if the green lights in both directions are on at the same time. It will then go into a yellow blink. </p>

<p>My idea is something like this: </p>

<pre class="lang-c prettyprint-override"><code>// Yellow blinking if fault in the system or operator activates it
int killState = digitalRead(Kill);
int resState = digitalRead(Res);
if (killState == HIGH /*|| greenlights in both directions */) {
 while (resState == LOW;) { // Yellow blink as long as system is not reset
  BLINK();
 }
}
</code></pre>

<p>I guess I need a variable or two that tells what state the lights are in, but I'm stuck. Any good solutions out there? </p>

<p>Another thing is the reset button. I haven't put much effort in it, but I want it to go into the starting point. </p>

<p>The link to the complete script can be found <a href="https://www.dropbox.com/s/evygp3w2gwvtxm9/lyskryss_v2.ino?dl=0" rel="nofollow">here.</a></p>
 13432: <p>For starters, take a close look at this line:</p>

<pre><code>while (resState == LOW;)
</code></pre>

<p>That is not the correct syntax. But the real issue is how is this while loop terminated? The value is never set again? </p>

<p>Cheers!</p>
 10794: <p>You could do something simple to test if both red and green are on,  eg.</p>

<pre><code>if (digitalRead (RED_PIN) == HIGH &amp;&amp; digitalRead (GREEN_PIN) == HIGH)
  {
  digitalWrite (RED_PIN, LOW);  // turn off red
  digitalWrite (GREEN_PIN, LOW);  // turn off green
  while (true)
    {
    digitalWrite (YELLOW_PIN, HIGH);
    delay (500);
    digitalWrite (YELLOW_PIN, LOW);
    delay (500);
    }  // end of while
  }  // end of it
</code></pre>

<hr>

<p>If you have other questions please post your code and not a <a href="http://snippets-r-us.com/" rel="nofollow">snippet</a> - however I suggest you try to get further on your own. This is obviously an exercise, and the more you try to work it out yourself the more you will learn.</p>
