Pages: [1]   Go Down
Author Topic: [RESOLVED] Serial monitor display formatting.  (Read 507 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: January 25, 2013, 10:33:00 am by eselin » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Serial.println ("Input   Output");
at the end of "setup ()".
Logged

"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.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That seems to be fancier than what AWOL suggested.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Pages: [1]   Go Up
Jump to: