Pages: [1]   Go Down
Author Topic: Input Response Timing  (Read 557 times)
0 Members and 1 Guest are viewing this topic.
N. Illinois
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?

Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

TX
Offline Offline
Jr. Member
**
Karma: 2
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

N. Illinois
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: