Hi guys, this is how far I have got with my coding for counting the pulses and incrementing the seconds+ minutes+ hours.but dont think its working as I expected when viewed through the serial monitor.
code;
int pulsePin = 3;
//int ledPin = 13;
unsigned long counter = 0;
unsigned long duration = 0;
unsigned long timeout = 1000000; // in microseconds
volatile int pulses;
volatile int seconds;
volatile int minutes;
volatile int hours;
void pulse_count() {
pulses++;
if (pulses = 50) {
pulses = 0; // reset
seconds ++;
}
// move forward one minute every 60 seconds
if (seconds >= 60) {
minutes++;
seconds = 0; // reset seconds to zero
Serial.println("minutes");
}
// move forward one hour every 60 minutes
if (minutes >= 60) {
hours++;
minutes = 0; //resets minutes to zero
}
if (hours >=24) {
hours = 0;
minutes = 0; // resets minutes to zero
}
}
void setup() {
pinMode(pulsePin, INPUT);
// enable the 20K pull-up resistor to steer
// the input pin to a HIGH reading.
digitalWrite(pulsePin, HIGH);
Serial.begin(9600);
attachInterrupt (1, pulse_count, RISING);
Serial.println("here we go");
}
void loop() {
duration = pulseIn(pulsePin, HIGH, timeout);
if (duration == 0) {
Serial.print("Pulse started before the timeout.");
Serial.println("");
} else {
counter++;
Serial.print(counter);
Serial.print(", ");
Serial.print(duration);
Serial.println(", ");
Serial.print(seconds);
Serial.println(", ");
Serial.print(minutes);
Serial.println(", ");
Serial.print(hours);
Serial.println(", ");
}
}
Any one find any problem, pls point out to me. 