I am coding for a large project on my Mega, so I gather in pieces from other sketches I’ve written so I can test them separately to make sure I have good code going into the larger. My problem now is when I test the smaller part of the sketch it compiles, uploads and does exactly what it’s supposed to;
boolean relayAstate = false;
if (now.hour() >= 6) relayAstate = true; // The test is true from 6-23, and false from 0-5 (18/6)
if (relayAstate == true)
{
digitalWrite(Relay_A, TURN_ON);
Serial.print("\t");
Serial.print(F("Vegetative Lights On")); // Text printed to serial monitor
Serial.print("\t");
Serial.println();
}
Now when I copy this over into the larger sketch, this block gives me errors. I get that I modified the code, but I believe I have the correct syntax? Can someone help me out?
boolean lightAstate = false;
if (now.hour() >= 6 && now.hour() <=17) lightAstate = true;
if (lightAstate == true)
{
digitalWrite(lightA, TURN_ON);
Serial.print("\t");
Serial.print(F("Bloom A Light On")); // Text printed to serial monitor
Serial.print("\t");
Serial.println();
}
The error is regarding the 2 ‘if’ statements, and the error is
I'm guessing that during the copy-paste, you added an extra brace or accidentally blatted one.
This is why we need al the code.
Incidentally: for this kind of code, convert hours/minutes into a single value "minutes past midnight", or even "minutes past the start of the week". Makes all the range checking much simpler.
I just tried to paste both sketches, but exceeded the 9000 character cap and it wouldn’t post. So I will attach the ino files. The error occurs on line 196 of skydro2, and that segment originated from line 126 of TIMEorCLIMATEswitching. Going through it again, I’ve found 2 extra curly braces that shouldn’t have been there, but after I removed them, still won’t compile. I’m stumped.
pert:
I recommend always doing Tools > Auto Format on your code. The automatic indentation will make it easy to spot the cause of these sorts of bugs.
Not only that, when you don't have matching { and }, the tool will tell you that. That makes YOU look at the code, and manually fix the indenting until you find where you screwed up.
pert:
I recommend always doing Tools > Auto Format on your code. The automatic indentation will make it easy to spot the cause of these sorts of bugs.
Yes , it's pretty good at that. Can't understand though why it's in the 'Tools' menu and not in the 'Edit' menu. Or, dare I say it, done automatically for you as part of 'copy for forum'. Or even (since the code behind the tool must be counting these things) warn you if the braces are mismatched.
Or perhaps the editor could do more inline syntax checking. I loaded the same code into the VisualMicro / VisualStudio editor and it highlighted the first 'if' after the erroneous closing brace.
Thank you so much everyone! The auto format function helped me to identify one additional mistake, but once fixed, it all compiles! Thank you again, very much!
Edit, it took me quite a few minutes to see how the } @ 190 was a mistake. It would help if I viewed the entire function instead of what was pasted in. Thanks quilkin