Serial monitor: Formatting output using the tab command
For quick and easy formatting spaces can be used but the output can become messy when the data has variable lengths. A better solution is the tab command “\t”. This works in exactly the same was as tab works in a word processor; it moves the cursor over to the next column and lines up the output.For this example there are button switches connected to pin 14(A0) and 15(A1) and a potentiometer on pin A3.
byte potPin = 17; byte switch1_pin = 14; byte switch2_pin = 15; int potVal = 0; boolean switch1State = 0; boolean switch2State = 0; void setup() { Serial.begin(115200); Serial.println(""); Serial.println("Pot\tSwitch1\tSwitch2"); } void loop() { potVal = analogRead(potPin); switch1State = digitalRead(switch1_pin); switch2State = digitalRead(switch2_pin); Serial.print(potVal); Serial.print("\t"); Serial.print(switch1State); Serial.print("\t"); Serial.println(switch2State); delay(500);Using tab means the columns stay aligned regardless of how small or large potVal is (not totally true. If the value becomes too large the tab character will move the cursor over to the next tab column).
Post A Comment:
0 comments:
Post a Comment