Pages: [1]   Go Down
Author Topic: Simultaneous Funtion/One-Shot Emulation  (Read 373 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's my dilemma:

I've written a program to quickly switch between receive and transmit states in a communications system.  The microprocessor is the Arduino Nano.  All is well until I want to pulse an LED as a one-shot for one second while the program continues to execute.  The LED will be used a visual fault indication, pulsed just long enough to show a system timing error.  And since this is a timing program with adjustable parameters changed in 1 msec increments, I cannot simply wait one second for the LED to turn off, then resume processing. 

What I want is (logically) simple: the ability to pulse an LED when an input pin changes state and stay that way for one second, while the program continues to execute.  Surely there must be some way of handling this with the Arduno microcontroller?

Ideas?  Thanks!

Paul 
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read and understand the Blink Without Delay example, then you will see how to program the Arduino to do several things at once.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Finland
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe have an interrupt on changing of the input pin state that affects a global state variable. Then in the loop() function you'd set the ledPin HIGH or LOW accordingly. You can have the interrupt only trigger on HIGH, and then mark the time on another variable, and in the loop you would set it LOW after that time stamp is far enough in the past.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read and understand the Blink Without Delay example, then you will see how to program the Arduino to do several things at once.

dc42 & Chaul,

Thanks for your responses.  The "Blink without Delay" command should do the trick.  It's odd that the command does not appear in my Arduino programming book.

Paul
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It's odd that the command does not appear in my Arduino programming book.
Which one would that be?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It's odd that the command does not appear in my Arduino programming book.
Which one would that be?

Monk, S., Programming Arduino - Getting Started with Sketches, ISBN 978-0-07-178422-1

Paul
Logged

Pages: [1]   Go Up
Jump to: