It takes twice as long to print "1023" (6 bytes, including the CRLF line terminator) than to print "0" (3 bytes). Thus, in the same time, you are printing twice as many "0" than "1023".
If you want the data points to be printed at a consistent rate,
you can impose the printing timing just like you did on the
output_state
. Keep in mind that you cannot print more than 20 samples
per second at 1200 bps. You could also pad the strings so that they
always have the same length:
char s[5]; // one byte for the NULL terminator
sprintf(s, "%4d", output_state);
Serial.println(s);
I would prefer the first solution (explicitly control the timing).
It takes twice as long to print "1023" (6 bytes, including the CRLF line terminator) than to print "0" (3 bytes). Thus, in the same time, you are printing twice as many "0" than "1023".
It takes twice as long to print "1023" (6 bytes, including the CRLF line terminator) than to print "0" (3 bytes). Thus, in the same time, you are printing twice as many "0" than "1023".
If you want the data points to be printed at a consistent rate,
you can impose the printing timing just like you did on the
output_state
. Keep in mind that you cannot print more than 20 samples
per second at 1200 bps. You could also pad the strings so that they
always have the same length:
char s[5]; // one byte for the NULL terminator
sprintf(s, "%4d", output_state);
Serial.println(s);
I would prefer the first solution (explicitly control the timing).
It takes twice as long to print "1023" (6 bytes, including the CRLF line terminator) than to print "0" (3 bytes). Thus, in the same time, you are printing twice as many "0" than "1023".