I have been writing code for measuring when the digital signal comes and goes (ON and OFF respectively). I have done the part calculating a single system's downtime (difference in timings between ON and OFF from the system), but when I'm not able to scale up to multiple systems when I try to copy the same code which worked above. So it would be helpful if anyone could provide some insight into how it can be done plus explaining with the code would help.
My code:
unsigned long a=0, b=0, difference;
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
Serial.print("start");
Serial.print(",");
Serial.print("stop");
Serial.print(",");
Serial.print("minutes");
Serial.print(",");
Serial.println("seconds");
}
void loop()
{
//delay(1000);
int A = digitalRead(2);
if(A == LOW)
{
b = millis();
}
if(A == HIGH)
{
a = millis();
display_output();
}
delay(3000);
}
void display_output()
{
int minutes, seconds, sec;
difference = a - b;
seconds = int(difference/1000);
if(seconds >= 60)
{
//sec = seconds;
seconds = seconds%60;
minutes = minutes+1;
}
//minutes = int(seconds/60);
Serial.print((a/1000)+1);
Serial.print(",");
Serial.print((b/1000)+1);
Serial.print(",");
// Serial.print(difference);
//Serial.print(",");
Serial.print(minutes);
Serial.print(",");
Serial.println(seconds);
//Serial.println(",");
}