Use the Arduino UNO with the DS1302 RTC Module to print the time on the serial monitor when it receives a continuous signal. I just want to get the start and end time. That is, I want to record the time when the signal is received and the time when it is interrupted.
I want to show this result:
Signal start time : YYYY/MM/DD HH:MM:SS
Signal break time : YYYY/MM/DD HH:MM:SS
I already tried a lot of codes but didn't find the solution.
If by continuous signal you just mean a pin changing from low to high and then back to low later (or high to low and back to high) you could probably draw on the approach taken in the state change detect example at file / examples / 2 digital in the ide. Just get it first to recognise those changes and report in the ide "start of signal" and "end of signal".
Now I'm using the iterative loop in order to do the code only once, because I didn't meet the condition on purpose, but because the code is inside the VOID LOOP, it wasn't applied correctly
What is the difference between them.
The problem here is that the iterative loop is in conflict with the void loop function. Because instead of working only once and checking the condition, it continues to work every time.
X=1 is an assignment. X==1 is a comparison. Putting an assignment in a loop condition doesn't make sense. Indeed, a comparison in a loop conditional makes no sense unless you change the condition within the loop.
I have no idea what you mean by "iterative loop is in conflict with the void loop function".
+1. My guess, since I have to guess, is that X is an integer and somewhere you increment it to change the flow of the code.
Entire sketch pls OR a complete small sketch, setup() through loop(), compiles &c., that we can run for ourselves, that shows your attempt to get the behaviour you seek.
Untested. See if you can run your finger through this to see how it works. And if it does what you want.
void printDateTime()
{
Serial.print(RTC.dayofmonth);
Serial.print("/");
Serial.print(RTC.month);
Serial.print("/");
Serial.print(RTC.year);
Serial.print(" ");
Serial.print(RTC.hours);
Serial.print(":");
Serial.print(RTC.minutes);
Serial.print(":");
Serial.println(RTC.seconds);
}
int printStatus() {
static int flag = 0;
if (Level <= 200) {
if (flag != -1) {
printDateTime();
Serial.println("Signal OFF ");
}
flag = -1;
}
else { // Level > 200
if (flag != 1) {
printDateTime();
Serial.println("Signal ON ");
}
flag = 1;
}
}
Sry, I don't usually like to hand you a fish. So do take a look. Just one of as many ways to do this as there are programmers, approximately.
It may print more than you want. You could code some hysteresis in there like your home thermostat employs so the A/C not be going on and off alla time.