Friday, 18 March 2016

How to print different variables in a straight line? (Arduino)

I was facing this problem when I was making something in which I wanted to count how many times it turned on a led, and I wanted to print all the variables in one line but coudn't do it.

I wrote this
Serial.print("Led has been turned on ");
Serial.println(counter);
Serial.print("times.");

and the result came out like the picture below.


After trying a bit I found the solution, and that was so simple. If you want to print something in the same line then just use Serial.print and if you want to print something in a new line then use Serial.println.

After using this
Serial.print("Motion has been ditected ");
Serial.print(counter);
Serial.print(" Times.");

 I got the result below.


I thought it would be helpful to share. :)

No comments:

Post a Comment