1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Arduino - Println </title>
<link rel='stylesheet' href='arduino.css' type='text/css' />
<meta name="verify-v1" content="TtxFIEJAB6zdJ509wLxjnapQzKAMNm9u0Wj4ho6wxIY=" />
</head>
<body>
<div id="page">
<!--PageHeaderFmt-->
<div id="pageheader">
<div class="title"><a href="http://www.arduino.cc"/>Arduino</a></div>
<div class="search">
<!-- SiteSearch Google -->
<FORM method=GET action="http://www.google.com/search">
<input type=hidden name=ie value=UTF-8>
<input type=hidden name=oe value=UTF-8>
<INPUT TYPE=text name=q size=25 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="search">
<input type=hidden name=domains value="http://www.arduino.cc/">
<input type=hidden name=sitesearch value="http://www.arduino.cc/">
</FORM>
<!-- SiteSearch Google -->
</div>
</div>
<!--/PageHeaderFmt-->
<!--PageLeftFmt-->
<div id="pagenav" style="text-align: right">
<div style="float: left;">
<p><a class='wikilink' href='http://arduino.cc/en/Main/Buy'>Buy</a>
|
<a class='wikilink' href='http://arduino.cc/en/Main/Software'>Download</a>
|
<a class='wikilink' href='Guide_index.html'>Getting Started</a>
|
<a class='wikilink' href='http://arduino.cc/en/Tutorial/HomePage'>Learning</a>
|
<a class='wikilink' href='index.html'>Reference</a>
|
<a class='wikilink' href='http://arduino.cc/en/Main/Hardware'>Hardware</a>
|
<a class='wikilink' href='FAQ.html'>FAQ</a>
</p>
<p class='vspace'></p>
</div>
<a class="urllink" href="http://www.arduino.cc/blog/" rel="nofollow">Blog »</a> |
<a class="urllink" href="http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl" rel="nofollow">Forum »</a> |
<a class="urllink" href="http://www.arduino.cc/playground/" rel="nofollow">Playground »</a>
</div>
<!--/PageLeftFmt-->
<div id="pagetext">
<!--PageText-->
<div id='wikitext'>
<h2>Serial.println(data)</h2>
<h4>Description</h4>
<p>Prints a data to the serial port, followed by a carriage return character(ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same forms as <a class='wikilink' href='Serial_Print.html'>Serial.print</a>():
</p>
<p class='vspace'></p><p><strong>Serial.println(b)</strong>
prints b as a decimal number in an ASCII string followed by a carriage return and a linefeed.
</p>
<p class='vspace'></p><p><strong>Serial.println(b, DEC)</strong>
prints b as a decimal number in an ASCII string followed by a carriage return and a linefeed.
</p>
<p class='vspace'></p><p><strong>Serial.println(b, HEX)</strong>
prints b as a hexadecimal number in an ASCII string followed by a carriage return and a linefeed.
</p>
<p class='vspace'></p><p><strong>Serial.println(b, OCT)</strong>
prints b as an octal number in an ASCII string followed by a carriage return and a linefeed.
</p>
<p class='vspace'></p><p><strong>Serial.println(b, BIN)</strong>
prints b as a binary number in an ASCII string followed by a carriage return and a linefeed.
</p>
<p class='vspace'></p><p><strong>Serial.print(b, BYTE)</strong>
prints b as a single byte followed by a carriage return and a linefeed.
</p>
<p class='vspace'></p><p><strong>Serial.println(str)</strong>
if str is a string or an array of chars, prints str an ASCII string.
</p>
<p class='vspace'></p><p><strong>Serial.println()</strong>
just prints a carriage return and a linefeed.
</p>
<p class='vspace'></p><h4>Parameter</h4>
<p>data types: integer types, including char, strings (char arrays) & floats<br />Printing of floats is supported with a precision of two places to the right of the decimal point.<br />This may change soon.
</p>
<p class='vspace'></p><h4>Returns</h4>
<p>None
</p>
<p class='vspace'></p><h4>Example:</h4>
<pre>
/*
Analog input
reads an analog input on analog in 0, prints the value out.
created 24 March 2006
by Tom Igoe
*/
int analogValue = 0; // variable to hold the analog value
void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog input on pin 0:
analogValue = analogRead(0);
// print it out in many formats:
Serial.println(analogValue); // print as an ASCII-encoded decimal
Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal
Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal
Serial.println(analogValue, OCT); // print as an ASCII-encoded octal
Serial.println(analogValue, BIN); // print as an ASCII-encoded binary
Serial.println(analogValue, BYTE); // print as a raw byte value
// delay 10 milliseconds before the next reading:
delay(10);
}
</pre>
<p class='vspace'></p><h4>Programming Tip / Known Issues</h4>
<p>see <a class='wikilink' href='Serial_Print.html'>Serial.print</a>
</p>
<p class='vspace'></p><h4>See also</h4>
<ul><li><a class='wikilink' href='ASCIIchart.html'>ASCII chart</a>
</li><li><a class='wikilink' href='Serial_Begin.html'>Serial.begin</a>(speed)
</li><li><a class='wikilink' href='Serial_Available.html'>Serial.available</a>()
</li><li><a class='wikilink' href='Serial_Read.html'>Serial.read</a>()
</li><li><a class='wikilink' href='Serial_Print.html'>Serial.print</a>(data)
</li></ul><p class='vspace'></p><p><a class='wikilink' href='index.html'>Reference Home</a>
</p>
</div>
</div>
<!--PageFooterFmt-->
<div id="pagefooter">
<a href='Serial_Println?action=edit.html'>Edit Page</a> | <a href='Serial_Println?action=diff.html'>Page History</a> | <a href='Serial_Println?action=print.html' target='_blank'>Printable View</a> | <a href='http://arduino.cc/en/Site/AllRecentChanges'>All Recent Site Changes</a>
</div>
<!--/PageFooterFmt-->
</div>
</body>
</html>
|