makes sense in the video? Isn't Serial always different from 0, because it's a static object that has a non-zero address? even if Serial.begin(9600) fails?
Jan Cumps Apparently, a reference to Serial in an if or while argument context evaluates to true if the specified serial port is available else there is a permanent/temporary error. There must be something hidden in the compilation/interpreter that treats Serial special. An if( Serial.isConnected() ) would be better. Secrets are bad engineering practices but what can you do? I cannot find any documentation of the static Serial object other than what's in the arduino.cc API. Have you?
To guard against a single spurious failure instance, I use this in setup() instead of the if-statement for Serial applications:
int count_down = 3; while( ! Serial ) { // Sleep 1 second if not yet ready. delay( 1000 ); // Tried the maximum allowed times already? if( count_down-- < 1 ) { // Tried 3 seconds to get the serial connection ready - giving up. // Timeout error processing goes here } }
So it looks like the bool operator is indeed overridden for the class HardwareSerial (also checked SoftwareSerial, it's the same mechanism there), but it always returns true, whatever the state of the connection
Ok, Jan Cumps earned the "King for the Day" title. I've been busy cleaning up my own mess (one of those "no good deed goes unpunished" stories).
King of which country? How about the USA? Stay longer. The American Congress is useless so we might as well have a King. And, you'd probably do a lot better than the 2 individuals currently running President in any case!
Ok, Jan Cumps earned the "King for the Day" title. I've been busy cleaning up my own mess (one of those "no good deed goes unpunished" stories).
King of which country? How about the USA? Stay longer. The American Congress is useless so we might as well have a King. And, you'd probably do a lot better than the 2 individuals currently running President in any case!
Top Comments
-
Jan Cumps
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
Former Member
in reply to Jan Cumps
-
Cancel
-
Vote Up
+1
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
Jan Cumps
in reply to Former Member
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
Jan Cumps
in reply to Former Member
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
Former Member
in reply to Jan Cumps
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
Jan Cumps
in reply to Former Member
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
Former Member
in reply to Jan Cumps
-
Cancel
-
Vote Up
+1
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Comment-
Former Member
in reply to Jan Cumps
-
Cancel
-
Vote Up
+1
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Children