title: Raspberry Pi, looping delay function
body: <p>This is my code:</p>
  
  <pre><code>#include &lt;wiringPi.h&gt;
  #include &lt;stdio.h&gt;
  
  #define LED 18
  #define IN 24
  
  int main(void)
  {
      wiringPiSetupGpio ();
      pinMode (LED, OUTPUT);
      pinMode (IN, INPUT);
      for (;;)
      {
          digitalWrite (LED, 1);
          delay (2000);
          digitalWrite (LED, 0);
          delay (2000);
  
          if (digitalRead (IN) == 1)
          {
              for (;;)
              {
                  digitalWrite (LED, 1);
                  delay(500);
                  digitalWrite (LED, 0);
                  delay(500);
  
              }
          }    
      }    
      return 0;
  }
  </code></pre>
  
  <p>I use a switch to go from the 2000 delay to the 500 delay. The problem is that when I press the switch it waits until the loop is over until it becomes faster. Same applies to vice versa. I need to write a function or a loop somewhere in my code that allows me to press the switch and immediately with no wait go to the slower/faster speed. I am coding this in C, on a raspberry pi using the wiring pi libraries, and gpio pin numbering. </p>