Hey everyone I need your help on how to set a time on when the arduino will read pulses. I want to make the arduino read how many high pulses it gets in 1 second then display it after that given time rather than displaying the high pulses incrementing. I'm using Arduino Mega 2560.
This is the code I used:
int pulsePin = 52;
int ledPin = 13;
unsigned long highCounter = 0;
int pulse = 0;
int lastPulse = LOW;
void setup() {
pinMode(pulsePin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pulsePin, HIGH);
Serial.begin(4800);
}
void loop() {
pulse = digitalRead(pulsePin);
if (pulse != lastPulse) {
digitalWrite(ledPin, pulse);
Serial.println(pulse);
lastPulse = pulse;
if (pulse == HIGH) highCounter++;
Serial.println(highCounter);
}
}
Thanks guix I tried the code you sent me and it diplayed after the time delay that was set
if ( millis() - oldMillis >= 1000 )
but when the pulses were sent mid the time frame it somehow displays the number of high pulses in 2 instances. So now what i want to do is to use 3 buttons and when button 1 is pressed it would wait for 1 pulse when button 2 is pressed it would wait for 5 pulses and if button 3 is pressed it would wait for 10 pulses. HELP! :