Interrupts

I know how to trigger an interrupt function through an external input, but can I have a software event trigger it? I was thinking of having the arduino wait 5 seconds for user input, then continue.

After an ISR completes. it returns to where it was executing - waiting for user input. So, I don't think that will help you.

How is the user to enter this input? There are ways to use millis() to determine how long you have been waiting, and stop waiting after a while.

Of course, this begs the question of why you are waiting for user input. The program should execute loop endlessly, noticing at some point that "Hey, there was user input".

I want to enter info through serial monitor, but the arduino will only echo it if it was typed inside of 5 seconds.

Five seconds after what?

If you are sending a prompt, you could do something like this:

bool sendPrompt = true;
unsigned long promptSent;

void loop()
{
   if(sendPrompt)
   {
      Serial.println("Enter a character:");
      promptSent = millis();
      sendPrompt = false;
   }

   while(Serial.available() > 0)
   {
      char inChar = Serial.read();
      if(millis() - promptSent < 5000)
      {
         Serial.print("You typed a ");
         Serial.println(inChar);
         sendPrompt = true;
      }
   }

   // Read a switch state. Set sendPrompt true if switch is pressed
}

Thanks! But how could I use interrupts? An example?

But how could I use interrupts

sp. "But why would I use interrupts?"

Run a program behind a foreground program!

Run a program behind a foreground program!

You're confusing an interrupt with a lower priority thread.

OK. Then how could I run two programs at once?

Then how could I run two programs at once?

Whoa! Mission creep.

Whatever. Could you please explain what interrupts are?

You're reading a book. The phone rings. You put a mark on the word you're reading. Pick up the phone and talk. Finish the call. Pick up the book, look at the mark where you were reading. Read the rest of the book.

That's an interrupt.

An interrupt in Arduino: http://arduino.cc/en/Reference/AttachInterrupt Thank you, kind sir AWOL. Can this allow me to use the TVout http://code.google.com/p/arduino-tvout/ Library to display images + tone() to play sounds?

You're reading a book. The phone rings. You put a mark on the word you're reading. Pick up the phone and talk. Finish the call. Pick up the book, look at the mark where you were reading. Read the rest of the book.

That's an interrupt.

Wow, the best example I've ever seen =)

About the opening question, you can fire an external interrupt by software just putting the pin as "output"(pinMode) and getting the digital level you need (digitalWrite HIGH/LOW). Take care of what is connected in the other end, of course.

OK. Thank you.