Go Down

Topic: Input Response Timing (Read 594 times) previous topic - next topic

So I have a rather large program that I noticed would react to an input becoming true pretty fast, although there is a very noticeable (2~3 sec.) delay for the input to report back low? so I thought it must be my terrible code skills, so I wrote this test code
Code: [Select]
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(31, INPUT);
pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(31) == true){
    digitalWrite(13, HIGH);
  }
  else{
    digitalWrite(13, LOW);
  }
 
 
}


I get the same delay when I remove the 5v from input 31?  Can anyone explain this and how I can make it faster?


Erdin

Wich board do you use ? The Arduino Mega 2560 ?

How is the pin going low ?
Do you use a pull-down resistor of 10k ?
If nothing is connected to the input pin, the value read with digitalRead() could be anything.

modeller


I get the same delay when I remove the 5v from input 31? 


When you say "remove 5V" are you simply pulling the voltage wire or are you pulling it to ground?

If not pulling it to ground it will be floating and won't be a reliable value.

yes once again I was being an idiot.  I keep forgetting this is a microcontroller and not a industrial controller (PLC).  It was floating when I disconnected because I was not pulling it down.   :smiley-red:

Go Up