- 245
- 1
- 3
- 12
You have to invalidate the ‘state’state
variable when SerialSerial
is not available, otherwise you will produce strange behaviours.
if(Serial1.available() > 0){ state = Serial1.read(); } else { state =-1; // not valid }
if (Serial1.available() > 0) {
state = Serial1.read();
} else {
state = -1; // not valid
}
Also, you have to check ‘1’ and ‘0’serial values will be characters and, not 1 and 0integers, so compare with character values. ‘if (state == ‘1’), e.g.’,
if (state == '1')
You have to invalidate the ‘state’ variable when Serial is not available, otherwise you will produce strange behaviours.
if(Serial1.available() > 0){ state = Serial1.read(); } else { state =-1; // not valid }
Also, you have to check ‘1’ and ‘0’ characters and not 1 and 0 values. ‘if (state == ‘1’)..’
You have to invalidate the state
variable when Serial
is not available, otherwise you will produce strange behaviours.
if (Serial1.available() > 0) {
state = Serial1.read();
} else {
state = -1; // not valid
}
Also, serial values will be characters, not integers, so compare with character values, e.g.,
if (state == '1')
You have to invalidate the ‘state’ variable when Serial is not available, otherwise you will produce strange behaviours.
if(Serial1.available() > 0){ state = Serial1.read(); } else { state =-1; // not valid }
Also, you have to check ‘1’ and ‘0’ characters and not 1 and 0 values. ‘if (state == ‘1’)..’