I have 6 outputs that only need to be on for 25ms.
I was wondering is there a way of doing this with out code. Simple put I do a digitalWrite(X, HIGH), then 25ms latter it automatically turns off, with out writing code to turn it off. I akin it to a one shot.
Yes I could do a delay(25), with means I can not do any processing while waiting for the delay to expire. Which means I might miss a event throwing the logging into error.
I know an understand that I will have to set this function in the setup section of the sketch.
Just off the top of my head (there are probably more methods):
Use millis() to poll the amount of time that has passed. This would still require you to poll and manually toggle the output but your CPU won’t be stuck at a delay.
Using millis() and a poll function is the way I am going it. I just was wondering if there another way to do it with out polling.
I am a newbie to coding. I looked over interrupt in the ref manual, is way over my head. Also I don’t think it would work because I would need 6 interrupts one for each output. Which are turned on at different times.
It’s possible to create an interrupt to manipulate multiple pins while maintaining a relatively short interrupt duration. I don’t know how familiar you are with pointers, STL vectors and creating your own class (once again, not the only way to do it) but I would probably start there.
Interrupts is the way I would like to go, it’s the just writing the code is beyond my programing know how. STL vectors an my own class are all Greek to me. So I think I will stick to the polling method for the time being, unless some one is willing to help me with interrupts coding.
There is another reason why I want learn interrupt coding. My project is a data logger /controller for the high power rocketry hobby. This interrupt would happen when the USB cable is pulled, when the bird lifts off, starting the logging/control operations.
General rule of programming: make things as simple as needed to get it working. Complexity has no benefit on its own. If polling is good enough, use polling. Interrupts are generally most useful when you are doing something else that’s too time consuming to make polling feasible.
The project I am working on is a data logger, with a sample rate of 100 samples per second. Along with this logging of data it also control pyro tech devices (staging, smoke bomb, an recovery chutes). Right now the polling will work. The time it takes the check a pyro and turn off when necessary seems to be extremely short (less the 1msec). so for now I will use the polling method.
As the sketch grows while I interrelated the sensors ( Altimeter, Gps, and Accelerometer) into the sketch, I do not know how fast I can log data. With a Interrupt it would just write the data to SIM card then exit
I want to learn Interrupt because there is one that’s some what important. That is when USB cable is pulled because it starts the logging process. The cable is pulled when the bird lifts off. So the quicker I detect the pull the better. The Interrupt code is very simple and short. It record the time of the pull and set a logic variable (Logging) to true, then exit along with being disable (not need after the pull). . With Logging true the sketch will write the data on the SIM Card.
Back to pyros the polling method is the simplest and most reliable method, so I will use polling. As the sketch matures this might change.