Arduino. Why does my code work with a delay -


I have written a code that works for some reason when I delay it is considered a traffic light < / P>

  int switchState = 0; Zero setup () {pinomoda (5, output); // red light pinomoda (4, output); // Yellow Light Pinomoda (3, Output); // green light pinnedoda (2, input); // button, when pressed lights digital dual switch (5, high); } Zero loop () {switchState = digitalRead (2); If (switchstate == HIGH) {if (digitalRead (5) == HIGH) {// if light is red digital (5, less); // Turn off the red light digital (3, high); // Turn ON the Deer Light Delay (500); // it is late} and {// light is green digital (3, less); // Close the Green Light Digital White (4, high); // Turn on yellow light delay (500); // Yellow light is turned on for a little like traffic light digital wight (4, lo); // Write Off Yellow Light Digital (5, High); // Turn on the red light}}}  

I thought it was because I had placed a "very long" button and ran the loop twice and adding delay I had made enough time Is it a matter to leave my finger or is anything else going on?

Edit: Without delay it will always jump on the second statement, even if the red light is turned on

It seems that you have some problems.

Do not switch off to open the button open, there is some jitter due to mechanical nature


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -