user20062: I have this simple push button schematic:

The idea is that the LED is on as long as the button stays pushed, with the switch closed.
The code is below:
int ledPin=10;
int switchPin=5;

void setup()

{
  Serial.begin(9600);
  pinMode(switchPin, INPUT);
  pinMode(ledPin,OUTPUT);

}
void loop()

{
  digitalWrite(ledPin,LOW);//DBG
  if (digitalRead(switchPin)==HIGH)
{
 digitalWrite(ledPin,HIGH);//DBG
 delay(500);
}
 if (digitalRead(switchPin)==LOW);
{
digitalWrite(ledPin,LOW);//DBG 
delay(200);
}
}

As I keep the button pressed, the LED blinks regularly, instead of staying on. Why?
I have tried using a capacitor between the switch and switchPin, with no change.

user2944: The beginning of your code in the loop:
void loop()  {
  digitalWrite(ledPin,LOW); //remove this line here
  if (digitalRead(switchPin)==HIGH)
{
     digitalWrite(ledPin,HIGH);//DBG
     delay(500);
}
 if (digitalRead(switchPin)==LOW);
 {
      digitalWrite(ledPin,LOW);//DBG 
       delay(200);
     }
}

Before your first if(digital read(switch pin) == HIGH)  you turn the LED off, and then you have a delay, which gives the blinking effect, remove that and it will not blink.

20062: <p>I have this simple push button schematic:
<a href="https://i.stack.imgur.com/sG0M7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sG0M7.png" alt="enter image description here" /></a></p>
<p>The idea is that the LED is on as long as the button stays pushed, with the switch closed.</p>
<p>The code is below:</p>
<pre><code>int ledPin=10;
int switchPin=5;

void setup()

{
  Serial.begin(9600);
  pinMode(switchPin, INPUT);
  pinMode(ledPin,OUTPUT);

}
void loop()

{
  digitalWrite(ledPin,LOW);//DBG
  if (digitalRead(switchPin)==HIGH)
{
 digitalWrite(ledPin,HIGH);//DBG
 delay(500);
}
 if (digitalRead(switchPin)==LOW);
{
digitalWrite(ledPin,LOW);//DBG 
delay(200);
}
}
</code></pre>
<p>As I keep the button pressed, <strong>the LED blinks regularly</strong>, instead of <strong>staying on</strong>. Why?
I have tried using a capacitor between the switch and switchPin, with no change.</p>
 2944: <p>The beginning of your code in the loop:</p>

<pre class="lang-cpp prettyprint-override"><code>void loop()  {
  digitalWrite(ledPin,LOW); //remove this line here
  if (digitalRead(switchPin)==HIGH)
{
     digitalWrite(ledPin,HIGH);//DBG
     delay(500);
}
 if (digitalRead(switchPin)==LOW);
 {
      digitalWrite(ledPin,LOW);//DBG 
       delay(200);
     }
}
</code></pre>

<p>Before your first <code>if(digital read(switch pin) == HIGH)</code>  you turn the LED off, and then you have a delay, which gives the blinking effect, remove that and it will not blink.</p>
