AmbroseNTK / simuino

Automatically exported from code.google.com/p/simuino
0 stars 0 forks source link

Strange results with Serial.print and Serial.println #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. write code for logging as Serial.print("\nSome Text")
2. write code for logging as Serial.println("This") and immediately after a 
serial.print(" is appended")
3. run the code and view output (ready-made example at foot of this report)

What is the expected output? What do you see instead?
1. Not sure if this is a console issue (linux) or a simuino issue (code)
2. Serial.println appends output to Serial.print <-- this may actually be as it 
is intended. I havent seen the specific specs around from Arduino on how this 
should behave, so may actually be correct operation. Please ignore if this is 
the case or amend accordingly. 

What version of the product are you using? On what operating system?
0.9.3 (Latest) Linux (Ubuntu)

Please provide any additional information below.

// simuino: Simuino_simple(Karls-Version)-V0.1
// (breakdown version of simple_simuino.c)

// PINMODE_IN:   1   "Pin 1  : Switch (in)"
// PINMODE_OUT: 13   "Pin 13 : LED   (out)"

// DIGITALWRITE_LOW:  13  "Turn LED off"
// DIGITALWRITE_HIGH: 13  "Turn LED ON"

// ANALOGREAD: 0  "Reading Analogue input"

// ========== End of Simuino Lines ===============

void test()
{
  Serial.print("\nAnalogue signal received!");
  Serial.print("\ntest function on interrupt");
  digitalWrite(13,HIGH);
  digitalWrite(13,LOW);
}

void setup()
{
  // int i;

  Serial.begin(9600);

  pinMode( 1,INPUT);
  pinMode(13,OUTPUT);

  attachInterrupt(0, test, CHANGE); // Interrupt 0 is using pin 2
}

void loop()
{
  int x;
  x = digitalRead(1);
  Serial.print("Pin 1 = ");
  Serial.println(x);

  if(x == HIGH)
    {
      digitalWrite(13,HIGH);
    }
  else
    {
      digitalWrite(13,LOW);
    }

  x = analogRead(0);
  Serial.print("Analog Pin 0 = ");
  Serial.println(x);
  if(x == HIGH)
    {
      digitalWrite(13,HIGH);
    }

}

Original issue reported on code.google.com by karl.but...@2ergo.com on 24 Nov 2011 at 9:10

GoogleCodeExporter commented 8 years ago
Serial.print will write without a "new-line" character.
Serial.println will write with a "new-line" character.
So, I would recommend not to use "\n" in the string you write. Use print/prntln 
instead. 

Original comment by benny.sa...@gmail.com on 24 Nov 2011 at 10:05

GoogleCodeExporter commented 8 years ago
No action!

Original comment by benny.sa...@gmail.com on 27 Nov 2011 at 8:30