Go Down

Topic: [RESOLVED] Serial monitor display formatting. (Read 568 times) previous topic - next topic

eselin

Jan 25, 2013, 04:03 pm Last Edit: Jan 25, 2013, 04:33 pm by eselin Reason: 1
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

AWOL

Code: [Select]
  valIn = analogRead(0);
  valOut = valIn/4;
  Serial.print(valIn);
  Serial.print (" ");
  analogWrite(LED, valOut); // PWM -- see API
  Serial.println(valOut);
  delay(10);
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

eselin

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

AWOL

Quote
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
Code: [Select]
Serial.println ("Input   Output"); at the end of "setup ()".
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

eselin

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

michinyon

That seems to be fancier than what AWOL suggested.

AWOL

To be fair, the tabs should make the columns more regular.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up