user11015: Disabling a push button after being under pressure for some time?
I need to disable a button where the user is pressing for a time it is disabled.
Code:
int ledPin = 13; 

int inPin = 7; 

int val = 0; 

void setup() {

pinMode(ledPin, OUTPUT); 

pinMode(inPin, INPUT); 

}

void loop(){

val = digitalRead(inPin);

if (val == HIGH) {

digitalWrite(ledPin, LOW);

} else {

digitalWrite(ledPin, HIGH); 

}

}


user2881: int ledPin = 13; 
int inPin = 7; 
int val = 0;
int oldVal = 0;

void setup() {
  pinMode(ledPin, OUTPUT); 
  pinMode(inPin, INPUT); 
}

void loop(){
  val = digitalRead(inPin);
  if (val == HIGH && oldVal == LOW) {
    digitalWrite(ledPin, LOW);
    oldVal = HIGH;
  } else if (val == LOW && oldVal == HIGH) {
    digitalWrite(ledPin, HIGH); 
    oldVal = LOW;
  }
}


11015: <p>Disabling a push button after being under pressure for some time?</p>

<p>I need to disable a button where the user is pressing for a time it is disabled.</p>

<p>Code:</p>

<pre><code>int ledPin = 13; 

int inPin = 7; 

int val = 0; 

void setup() {

pinMode(ledPin, OUTPUT); 

pinMode(inPin, INPUT); 

}

void loop(){

val = digitalRead(inPin);

if (val == HIGH) {

digitalWrite(ledPin, LOW);

} else {

digitalWrite(ledPin, HIGH); 

}

}
</code></pre>
 2881: <pre><code>int ledPin = 13; 
int inPin = 7; 
int val = 0;
int oldVal = 0;

void setup() {
  pinMode(ledPin, OUTPUT); 
  pinMode(inPin, INPUT); 
}

void loop(){
  val = digitalRead(inPin);
  if (val == HIGH &amp;&amp; oldVal == LOW) {
    digitalWrite(ledPin, LOW);
    oldVal = HIGH;
  } else if (val == LOW &amp;&amp; oldVal == HIGH) {
    digitalWrite(ledPin, HIGH); 
    oldVal = LOW;
  }
}
</code></pre>
