0

I have an infinite loop issue that keeps persisting in this code on my Teensy 3.1. This program is intended to take an input on Pin 0 and press the Enter key on the computer it is hooked into.

It is connected to a wire with no current but once a switch is flipped it should send a 5v Digital Signal blip to the Teensy and trigger it to run. It does function but it keeps getting caught in an infinite loop for some reason. Any help would be greatly appreciated!

// Global Variable
int signal_receiving_pin = 0;
void setup() { 
 // Outputting for error checking
 Serial.begin(38400);
 // Readying the pin for input
 pinMode(signal_receiving_pin, INPUT);
}
void loop() 
{ 
// If statement to check whether an input has been received
if (digitalRead(signal_receiving_pin) == HIGH)
{
 // If the signal has been detected..
 Serial.println("The signal has been received \n");
 Serial.println("Now sending the ENTER signal \n");
 // .. The ENTER key is sent to the computer 
 //Keyboard.press(KEY_ENTER);
 //Keyboard.release(KEY_ENTER);
 // Waiting 1 minute before allowing more input
 //delay(60000); // Pause
}
else
{
 // If the signal is not detected..
 // it will let you know it isn't there
 Serial.println("Input not detected \n");
}
}
asked Jan 8, 2018 at 21:23
1
  • Do you have a pulldown resistor? Commented Jan 8, 2018 at 21:29

1 Answer 1

0

Try using the internal Pullup/Pulldown resistor to control the input when the pin is not connected to anything. If you do not have a pullup/pulldown, then the input capacitance on the input pin circuitry can sample and hold the 5V unreliably.

...
void setup() { 
 // Outputting for error checking
 Serial.begin(38400);
 // Readying the pin for input
 pinMode(signal_receiving_pin, INPUT_PULLDOWN);
}
...

You may want to uncomment the delay() or add some state logic trigger only one activation per each cycle of signal_receiving_pin

answered Jan 8, 2018 at 21:54
1
  • 1
    Just changing to INPUT_PULLDOWN solved my problem! Thank you good sir! Commented Jan 10, 2018 at 13:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.