[RESOLVED] Serial monitor display formatting.

Hi from an Arduino newbie,

Am wanting to display both input and output values for a simple learning project reading the input values of a photoresistor and the output values to a LED. My code looks like this:

int valIn = 0; // input value from the sensor int valOut = 0; int LED = 9; // The LED test lamp connects to this PWM pin.

void setup() {

pinMode(LED, OUTPUT); Serial.begin(9600);

}

void loop() {

valIn = analogRead(0); valOut = valIn/4; Serial.println(valIn); analogWrite(LED, valOut); // PWM -- see API Serial.println(valOut); delay(10);

}

This works, only the Serial monitor shows it as a single column of values alternating input/output.

In the past few days have been writing a large number of short learning programs like this, including an earlier version of the above (which got accidentally overwritten) which showed the input and output values in two separate columns in the Serial monitor.

How is this done? I really do prefer the two-column presentation.

Thanks,

Eselin

  valIn = analogRead(0);
  valOut = valIn/4;
  Serial.print(valIn);
  Serial.print (" ");
  analogWrite(LED, valOut); // PWM -- see API
  Serial.println(valOut);
  delay(10);

OK, thanks, but this isn't it. What I had (my apologies, I don't remember from where) gave me output in two distinct columns, each column labelled "Input" and "Output" at the top, with the relevant values on the same line. It didn't involve any fancy or lengthy coding. Am studying the Arduino Cookbook but haven't yet found any general instructions on formatting the Serial monitor display.

Eselin

What I had (my apologies, I don't remember from where) gave me output in two distinct columns

What does the code I just gave you do? If you want labels (they're going to scroll away very quickly) is put a Serial.println ("Input  Output"); at the end of "setup ()".

eselin: the relevant values on the same line. It didn't involve any fancy or lengthy coding

AWOL's example displays the relevant values on the same line and doesn't involve any fancy or lengthy coding.

Ok, many thanks to all ...

I found the original example I had used and with the help of various instructional material which I have at hand was able to write the code I was looking for:

valIn = analogRead(0); valOut = valIn/4; Serial.print("Sensor value = "); Serial.print(valIn); Serial.print(" \t output = "); Serial.print(" "); analogWrite(LED, valOut); // PWM -- see API Serial.println(valOut); delay(10);

I think I understand the basic formatting principles now.

eselin

That seems to be fancier than what AWOL suggested.

To be fair, the tabs should make the columns more regular.