I've tried using millis to do this, but when i examine the pulses on separate software it seems the pin only stays on for 80 microseconds. Any suggestions?
delay(...) could work and is easier, but millis() is better in the long run. I applaud your use of millis(), but...
(1) You write about a 2 ms pulse, but there is nothing in the sketch to handle 2 ms.
(2) millis() on my Uno does not start at zero by the time that I get to it. Your first period (or first pulse length) will be short unless previousMillis is set up in the setup() function.
(3) It would help to have a variable that keeps track of whether you are outputting a pulse or waiting in the period between pulses. There is a way to avoid this but requires reading the state of pin 8 (which some experts deplore).
(4) Pins should have names and the names should be well chosen and used. There should be a global line similar to const byte pulseOut=8; and then pulseOut should be used everywhere we see that pin 8 is referred to.
But it will not be extremely accurate due to slight delays in performing the logic shifts. You can measure how inaccurate it is and tweak it or express your pleasure or displeasure with the above simple approach.
delay(...) and delayMicroseconds(...) are easier than millis() and micros() but will introduce issues if there are other things that you want to add later.
It would be nice to know how accurate the 2 ms and the 998 ms need to be.
i'm very new but it would seem to me that you could just use the basic example for Blink...and just modify the delay counts and pin assignment or just use pin 13 instead
vaj4088:
delay(...) could work and is easier, but millis() is better in the long run. I applaud your use of millis(), but...
(1) You write about a 2 ms pulse, but there is nothing in the sketch to handle 2 ms.
(2) millis() on my Uno does not start at zero by the time that I get to it. Your first period (or first pulse length) will be short unless previousMillis is set up in the setup() function.
(3) It would help to have a variable that keeps track of whether you are outputting a pulse or waiting in the period between pulses. There is a way to avoid this but requires reading the state of pin 8 (which some experts deplore).
(4) Pins should have names and the names should be well chosen and used. There should be a global line similar to const byte pulseOut=8; and then pulseOut should be used everywhere we see that pin 8 is referred to.
Thanks for the advice.
The reason I used millis was because this program will use analogRead to read a voltage during those 2ms that the pin is on, and then make a decision on what to output based on that voltage. Delay would not be able to work because it pauses the program.