user68205: I'm an absolute beginner, and lately I had some problem with this program I was trying to do.
Basically I wanted with the Arduino to count 3 pulses from an oscillator and store the time  of these 3 pulses, but as I said I am a beginner so I have no Idea on how to do it, I would appreciate your help.

user66535: Simple code
int pin = 7;
unsigned long duration;

void setup() {
  Serial.begin(9600);
  pinMode(pin, INPUT);
}

void loop() {
long duration = pulseIn(pin, HIGH);
 Serial.println(duration);
//delay(100);
}

Assuming that you are mentioning a squrewave this code mesures the time that squrewave pulse stays in HIGH and prints out in computer serial monitor.
You should send the signal to digital pin 7 (or put any pin you won't modify code int pin = 7;) 5 V HIGH and 0 V LOW.
The time unit measuring in here is in microseconds.
If you won't to measure low then pulseIn(pin, LOW);
I took the example from Arduino official site you can refer more here
https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/
Remember this is the basic example there are other good methods than this...
Analog wave is bit too complex.

user68475: While this is likely to need tweaks for your needs, it should get you looking at the right things - millis, interrupts, etc.
Official references at:
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
https://www.arduino.cc/reference/en/language/functions/time/millis/

#define pulsesToStore 3
#define interruptPin 2
volatile unsigned char index;
unsigned long storedTimes[pulsesToStore];

void restartStorage() {
 index = 0;
 attachInterrupt(digitalPinToInterrupt(interruptPin), storeTime, RISING);
}

void storeTime() {
 storedTimes[index] = millis();
 index = index + 1;
 if(index >= pulsesToStore) { //stop storage
  detachInterrupt(digitalPinToInterrupt(interruptPin));
 }
}

void setup() {
 pinMode(interruptPin, INPUT_PULLUP);
 restartStorage();
}

void loop() {
  // does nothing for now.  this is where you would do something with the stored pulses, print to serial, etc.
}



68205: <p>I'm an absolute beginner, and lately I had some problem with this program I was trying to do.
Basically I wanted with the Arduino to count 3 pulses from an oscillator and store the time  of these 3 pulses, but as I said I am a beginner so I have no Idea on how to do it, I would appreciate your help.</p>
 66535: <p>Simple code</p>
<pre><code>int pin = 7;
unsigned long duration;

void setup() {
  Serial.begin(9600);
  pinMode(pin, INPUT);
}

void loop() {
long duration = pulseIn(pin, HIGH);
 Serial.println(duration);
//delay(100);
}
</code></pre>
<p>Assuming that you are mentioning a squrewave this code mesures the time that squrewave pulse stays in <code>HIGH</code> and prints out in computer serial monitor.</p>
<p>You should send the signal to digital pin 7 (or put any pin you won't modify code <code>int pin = 7;</code>) 5 V HIGH and 0 V LOW.</p>
<p>The time unit measuring in here is in microseconds.
If you won't to measure low then <code>pulseIn(pin, LOW);</code></p>
<p><strong>I took the example from Arduino official site you can refer more here</strong></p>
<p><a href="https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/" rel="nofollow noreferrer">https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/</a></p>
<p>Remember this is the basic example there are other good methods than this...</p>
<p>Analog wave is bit too complex.</p>
 68475: <p>While this is likely to need tweaks for your needs, it should get you looking at the right things - millis, interrupts, etc.
Official references at:
<a href="https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/" rel="nofollow noreferrer">https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/</a>
<a href="https://www.arduino.cc/reference/en/language/functions/time/millis/" rel="nofollow noreferrer">https://www.arduino.cc/reference/en/language/functions/time/millis/</a></p>
<pre><code>
#define pulsesToStore 3
#define interruptPin 2
volatile unsigned char index;
unsigned long storedTimes[pulsesToStore];

void restartStorage() {
 index = 0;
 attachInterrupt(digitalPinToInterrupt(interruptPin), storeTime, RISING);
}

void storeTime() {
 storedTimes[index] = millis();
 index = index + 1;
 if(index &gt;= pulsesToStore) { //stop storage
  detachInterrupt(digitalPinToInterrupt(interruptPin));
 }
}

void setup() {
 pinMode(interruptPin, INPUT_PULLUP);
 restartStorage();
}

void loop() {
  // does nothing for now.  this is where you would do something with the stored pulses, print to serial, etc.
}

</code></pre>
