Question: Can this hurt my Mega Arduino board?
if
{
I’m going to use a simple flip flop circuit connected to Arduino Mega Digital Output pin to activate and Flash an LED when an “abort” interrupt is set by a momentary switch. I have code that I want to finish running when the abort is triggered but want the Main Power LED to blink while the code completes it cycle to indicate that an “Abort” was called.
During normal operation the LED is lit using a digitalWrite(LEDS,HIGH);. The same LED will also be wired to the output of the flip flop 5V circuit. The Flip Flop circuit board will be connected to a different Arduino Output Pin and activated via
digitalWrite(LEDS,LOW); //turn off the LED
digitalWrite (LEDF,HIGH).; // power the Flip flop circuit with 5V
When the “abort is called”
For less the $0.75 I can solder up 2 LEDs, 2 Capacitors, 4 resistors, and 2 Transistors to create the flip flop circuit that alternates the LEDS on and off. Ill display one of the LEDs on the outside and the other inside my cabinet box.
I looked at other posted code that uses system timers to blink two LEDs at the same time without using delay(); but this won’t work well for me. The other code I have to compete running is complicated .
My Question is when I activate the flip flop circuit an alternating 0 to 5v will also be applied to the designated OUTPUT Pin LEDS of the Arduino.
Can this hurt my Mega Arduino board?
}
Else
{
Does Arduino have a Library function “called Flash” that runs in the background when called to alternate the OUTPUT Pin High Low at a “flashing” pace?
Seems like more trouble than just getting the Arduino to flash the LED. You can use the millis() timer or use an Arduino timer with an interrupt to toggle the LED output every time the interrupt runs. In fact, on the Mega you have several timers available. Set up a timer with an ISR like this:
Certain output pins can be configured to be driven directly from an internal timer - thus, blinking without any software action at all except for the initial setup. But it's not recommended for beginners.
All quite unnecessary. The whole point of uisng a microcontroller is to do many things effectively simultaneously.
If your "abort" is to be handled in code, then you can flash your LED at the same time. Further, it is a common "newbie" blunder to imagine that an interrupt is either necessary or even in any way suitable to do this.
Paul__B:
If your "abort" is to be handled in code, then you can flash your LED at the same time. Further, it is a common "newbie" blunder to imagine that an interrupt is either necessary or even in any way suitable to do this.
It is not necessary to use an interrupt to blink an LED, but why is it not suitable as you put it? If you have an unused timer then why not? Just wondering...
As a beginner, it is incredibly unlikely that interrupts will be useful to you.
A common "newbie" misunderstanding is that an interrupt is a mechanism for altering the flow of a program - to execute an alternate function. Nothing could be further from the truth!
An interrupt is a mechanism for performing an action which can be executed in "no time at all" with an urgency that it must be performed immediately or else data - information - will be lost or some harm will occur. It then returns to the main task without disturbing that task in any way though the main task may well check at the appropriate point for a "flag" set by the interrupt.
Now these criteria are in a microprocessor time scale - microseconds. This must not be confused with a human time scale of tens or hundreds of milliseconds or indeed, a couple of seconds. A switch operation is in this latter category and a mechanical operation perhaps several milliseconds; the period of a 6000 RPM shaft rotation is ten milliseconds.
Unless it is a very complex procedure, you would expect the loop() to cycle many times per millisecond. If it does not, there is most likely an error in code planning; while the delay() function is provided for testing purposes, its action goes strictly against effective programming methods. The loop() will be successively testing a number of contingencies as to whether each requires action, only one of which may be whether a particular timing criteria has expired. Unless an action must be executed in the order of microseconds, it will be handled in the loop().
So what sort of actions do require such immediate attention? Well, generally those which result from the computer hardware itself, such as high speed transfer of data in UARTs(, USARTs) or disk controllers.
An alternate use of interrupts, for context switching in RTOSs, is rarely relevant to this category of microprocessors as it is more efficient to write cooperative code as described above.
Paul__B:
As a beginner, it is incredibly unlikely that interrupts will be useful to you.
I was just wondering why interrupts are not suitable for blinking an LED. I was suggesting to the OP it would be way easier to use a spare timer to blink the LED rather than external hardware but I was not suggesting it was the only way either. For myself, I've done it in several projects and it results in code that is more readable due to it not being cluttered with main loop code reading the millis() timer and toggling the LED state. Turning the LED on is as simple as enabling or disabling the interrupt for that timer, or starting and stopping the timer, etc.
I highly doubt toggling the LED state and a single digitalWrite in an ISR will affect the performance of the system.
ToddL1962:
For myself, I've done it in several projects and it results in code that is more readable due to it not being cluttered with main loop code reading the millis() timer and toggling the LED state.
I solved that issue by creating functions to do things like that. The main loop then looks cleaner than it ever did.
ToddL1962:
Turning the LED on is as simple as enabling or disabling the interrupt for that timer, or starting and stopping the timer, etc.
Really? Suppose you want to turn it off... you disable the interrupt. If the LED was on, it will stay on, if off, it will stay off. That is not useful control.
aarg:
Really? Suppose you want to turn it off... you disable the interrupt. If the LED was on, it will stay on, if off, it will stay off. That is not useful control.
I know that. I was in a hurry when I typed my response. I built a lathe controller with an Arduino Mega where I use a spare timer for an LED. I turn the LED off after I disable the interrupt. It works fine. If I need the timer I can change it. 6 of one, half dozen of the other for my application.
I am not some newbie dumb ass. I've been programming microcontrollers for 35 years for everything from closed loop controllers for hydro and nuclear power production to rocket guidance and navigation systems.
I can tell by your condescending attitude you are one of those people who think your way is the only way. Whatever...SMH wildly.