194 lines
		
	
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			194 lines
		
	
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 | 
						|
<html>
 | 
						|
<head>
 | 
						|
  <title>Arduino - Reference </title>
 | 
						|
  <link rel='stylesheet' href='arduino.css' type='text/css' />
 | 
						|
</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='selflink' 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'>
 | 
						|
<p><strong>Reference</strong>    <a class='selflink' href='index.html'>Language</a> (<a class='wikilink' href='Extended.html'>extended</a>) | <a class='wikilink' href='Libraries.html'>Libraries</a> | <a class='wikilink' href='Comparison.html'>Comparison</a>
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><h1>Language Reference</h1>
 | 
						|
<p><em>See the <strong><a class='wikilink' href='Extended.html'>extended reference</a></strong> for more advanced features of the Arduino languages and the <strong><a class='wikilink' href='Libraries.html'>libraries page</a></strong> for interfacing with particular types of hardware. </em>
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><p>Arduino programs can be divided in three main parts: <em>structure</em>, <em>values</em> (variables and constants), and <em>functions</em>.  The Arduino language is based on C/C++.
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><p>Here's a <a class='wikilink' href='StyleGuide.html'>style guide</a> that helps with writing examples for beginners.
 | 
						|
</p>
 | 
						|
<p class='vspace'></p>
 | 
						|
<table  width='100%' border='0' cellpadding='5' cellspacing='0'><tr><td  width='50%' valign='top'>
 | 
						|
<h2>Structure</h2>
 | 
						|
<ul><li>void <a class='wikilink' href='Setup.html'>setup</a>()
 | 
						|
</li><li>void <a class='wikilink' href='Loop.html'>loop</a>()
 | 
						|
</li></ul><p class='vspace'></p><h4>Control Structures</h4>
 | 
						|
<ul><li><a class='wikilink' href='If.html'>if</a>
 | 
						|
</li><li><a class='wikilink' href='Else.html'>if...else</a>
 | 
						|
</li><li><a class='wikilink' href='For.html'>for</a>
 | 
						|
</li><li><a class='wikilink' href='SwitchCase.html'>switch case</a>
 | 
						|
</li><li><a class='wikilink' href='While.html'>while</a>
 | 
						|
</li><li><a class='wikilink' href='DoWhile.html'>do... while</a>
 | 
						|
</li><li><a class='wikilink' href='Break.html'>break</a>
 | 
						|
</li><li><a class='wikilink' href='Continue.html'>continue</a>
 | 
						|
</li><li><a class='wikilink' href='Return.html'>return</a>
 | 
						|
</li></ul><p class='vspace'></p><h4>Further Syntax</h4>
 | 
						|
<ul><li><a class='wikilink' href='SemiColon.html'>;</a> (semicolon)
 | 
						|
</li><li><a class='wikilink' href='Braces.html'>{}</a> (curly braces)
 | 
						|
</li><li><a class='wikilink' href='Comments.html'>//</a> (single line comment)
 | 
						|
</li><li><a class='wikilink' href='Comments.html'>/* */</a> (multi-line comment)
 | 
						|
</li></ul><p class='vspace'></p><h4>Arithmetic Operators</h4>
 | 
						|
<ul><li><a class='wikilink' href='Assignment.html'>= (assignment)</a>
 | 
						|
</li><li><a class='wikilink' href='Arithmetic.html'>+ (addition)</a>
 | 
						|
</li><li><a class='wikilink' href='Arithmetic.html'>-  (subtraction)</a>
 | 
						|
</li><li><a class='wikilink' href='Arithmetic.html'>* (multiplication)</a>
 | 
						|
</li><li><a class='wikilink' href='Arithmetic.html'>/ (division)</a>
 | 
						|
</li><li><a class='wikilink' href='Modulo.html'>% (modulo)</a>
 | 
						|
</li></ul><p class='vspace'></p><h4>Comparison Operators</h4>
 | 
						|
<ul><li><a class='wikilink' href='If.html'>==</a> (equal to)
 | 
						|
</li><li><a class='wikilink' href='If.html'>!=</a> (not equal to)
 | 
						|
</li><li><a class='wikilink' href='If.html'><</a> (less than)
 | 
						|
</li><li><a class='wikilink' href='If.html'>></a> (greater than)
 | 
						|
</li><li><a class='wikilink' href='If.html'><=</a> (less than or equal to)
 | 
						|
</li><li><a class='wikilink' href='If.html'>>=</a> (greater than or equal to)
 | 
						|
</li></ul><p class='vspace'></p><h4>Boolean Operators</h4>
 | 
						|
<ul><li><a class='wikilink' href='Boolean.html'>&&</a> (and)
 | 
						|
</li><li><a class='wikilink' href='Boolean.html'>||</a> (or)
 | 
						|
</li><li><a class='wikilink' href='Boolean.html'>!</a> (not)
 | 
						|
</li></ul><p class='vspace'></p><h4>Compound Operators</h4>
 | 
						|
<ul><li><a class='wikilink' href='Increment.html'>++</a> (increment)
 | 
						|
</li><li><a class='wikilink' href='Increment.html'>--</a> (decrement)
 | 
						|
</li><li><a class='wikilink' href='IncrementCompound.html'>+=</a> (compound addition)
 | 
						|
</li><li><a class='wikilink' href='IncrementCompound.html'>-=</a> (compound subtraction)
 | 
						|
</li><li><a class='wikilink' href='IncrementCompound.html'>*=</a> (compound multiplication)
 | 
						|
</li><li><a class='wikilink' href='IncrementCompound.html'>/=</a> (compound division)
 | 
						|
</li></ul><p class='vspace'></p><h2>Variables</h2>
 | 
						|
<p>Variables are expressions that you can use in programs to store values, such as a sensor reading from an analog pin.  
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><h4>Constants</h4>
 | 
						|
<p>Constants are particular values with specific meanings.  
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><ul><li><a class='wikilink' href='Constants.html'>HIGH</a> | <a class='wikilink' href='Constants.html'>LOW</a>
 | 
						|
</li><li><a class='wikilink' href='Constants.html'>INPUT</a> | <a class='wikilink' href='Constants.html'>OUTPUT</a>
 | 
						|
</li><li><a class='wikilink' href='Constants.html'>true</a> | <a class='wikilink' href='Constants.html'>false</a>
 | 
						|
<p class='vspace'></p></li><li><a class='wikilink' href='IntegerConstants.html'>Integer Constants</a>
 | 
						|
</li></ul><p class='vspace'></p><h4>Data Types</h4>
 | 
						|
<p>Variables can have various types, which are described below.  
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><ul><li><a class='wikilink' href='BooleanVariables.html'>boolean</a>
 | 
						|
</li><li><a class='wikilink' href='Char.html'>char</a>
 | 
						|
</li><li><a class='wikilink' href='Byte.html'>byte</a>
 | 
						|
</li><li><a class='wikilink' href='Int.html'>int</a>
 | 
						|
</li><li><a class='wikilink' href='UnsignedInt.html'>unsigned int</a>
 | 
						|
</li><li><a class='wikilink' href='Long.html'>long</a>
 | 
						|
</li><li><a class='wikilink' href='UnsignedLong.html'>unsigned long</a>
 | 
						|
</li><li><a class='wikilink' href='Float.html'>float</a>
 | 
						|
</li><li><a class='wikilink' href='Double.html'>double</a>
 | 
						|
</li><li><a class='wikilink' href='String.html'>string</a>
 | 
						|
</li><li><a class='wikilink' href='Array.html'>array</a>
 | 
						|
</li><li><a class='wikilink' href='Void.html'>void</a>
 | 
						|
</li></ul><p class='vspace'></p><h4>Conversion</h4>
 | 
						|
<ul><li><a class='wikilink' href='CharCast.html'>char()</a>
 | 
						|
</li><li><a class='wikilink' href='ByteCast.html'>byte()</a>
 | 
						|
</li><li><a class='wikilink' href='IntCast.html'>int()</a>
 | 
						|
</li><li><a class='wikilink' href='LongCast.html'>long()</a>
 | 
						|
</li><li><a class='wikilink' href='FloatCast.html'>float()</a>
 | 
						|
</li></ul><p class='vspace'></p><h2>Reference</h2>
 | 
						|
<ul><li><a class='wikilink' href='ASCIIchart.html'>ASCII chart</a>
 | 
						|
</li></ul><p class='vspace'></p></td><td  width='50%' valign='top'> 
 | 
						|
<h2>Functions</h2>
 | 
						|
<p><strong>Digital I/O</strong>
 | 
						|
</p><ul><li><a class='wikilink' href='PinMode.html'>pinMode</a>(pin, mode)   
 | 
						|
</li><li><a class='wikilink' href='DigitalWrite.html'>digitalWrite</a>(pin, value) 
 | 
						|
</li><li>int <a class='wikilink' href='DigitalRead.html'>digitalRead</a>(pin)
 | 
						|
</li></ul><p class='vspace'></p><p><strong>Analog I/O</strong>
 | 
						|
</p><ul><li>int <a class='wikilink' href='AnalogRead.html'>analogRead</a>(pin)
 | 
						|
</li><li><a class='wikilink' href='AnalogWrite.html'>analogWrite</a>(pin, value) - <em>PWM</em>
 | 
						|
</li></ul><p class='vspace'></p><p><strong>Advanced I/O</strong>
 | 
						|
</p><ul><li><a class='wikilink' href='ShiftOut.html'>shiftOut</a>(dataPin, clockPin, bitOrder, value) 
 | 
						|
</li><li>unsigned long <a class='wikilink' href='PulseIn.html'>pulseIn</a>(pin, value)
 | 
						|
</li></ul><p class='vspace'></p><p><strong>Time</strong>
 | 
						|
</p><ul><li>unsigned long <a class='wikilink' href='Millis.html'>millis</a>()   
 | 
						|
</li><li>unsigned long <a class='wikilink' href='Micros.html'>micros</a>()
 | 
						|
</li><li><a class='wikilink' href='Delay.html'>delay</a>(ms)  
 | 
						|
</li><li><a class='wikilink' href='DelayMicroseconds.html'>delayMicroseconds</a>(us)
 | 
						|
</li></ul><p class='vspace'></p><p><strong>Math</strong>
 | 
						|
</p><ul><li><a class='wikilink' href='Min.html'>min</a>(x, y)
 | 
						|
</li><li><a class='wikilink' href='Max.html'>max</a>(x, y)
 | 
						|
</li><li><a class='wikilink' href='Abs.html'>abs</a>(x)
 | 
						|
</li><li><a class='wikilink' href='Constrain.html'>constrain</a>(x, a, b)
 | 
						|
</li><li><a class='wikilink' href='Map.html'>map</a>(value, fromLow, fromHigh, toLow, toHigh)
 | 
						|
</li><li><a class='wikilink' href='Pow.html'>pow</a>(base, exponent)
 | 
						|
</li><li><a class='wikilink' href='Sq.html'>sq</a>(x)
 | 
						|
</li><li><a class='wikilink' href='Sqrt.html'>sqrt</a>(x)
 | 
						|
</li></ul><p class='vspace'></p><p><strong>Trigonometry</strong> 
 | 
						|
</p><ul><li><a class='wikilink' href='Sin.html'>sin</a>(rad)
 | 
						|
</li><li><a class='wikilink' href='Cos.html'>cos</a>(rad)
 | 
						|
</li><li><a class='wikilink' href='Tan.html'>tan</a>(rad)
 | 
						|
</li></ul><p class='vspace'></p><p><strong>Random Numbers</strong>
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><ul><li><a class='wikilink' href='RandomSeed.html'>randomSeed</a>(seed)
 | 
						|
</li><li>long <a class='wikilink' href='Random.html'>random</a>(max)
 | 
						|
</li><li>long <a class='wikilink' href='Random.html'>random</a>(min, max)
 | 
						|
</li></ul><p class='vspace'></p><p><strong>Communication</strong>
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><ul><li><a class='wikilink' href='Serial.html'>Serial</a>
 | 
						|
</li></ul><p class='vspace'></p><p><br clear='all' />
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><p><strong>Didn't find something?</strong>  Check the <a class='wikilink' href='Extended.html'>extended reference</a> or the <a class='wikilink' href='Libraries.html'>libraries</a>.  Or see the list of <a class='urllink' href='http://www.arduino.cc/playground/Main/GeneralCodeLibrary' rel='nofollow'>community-contributed code</a>.
 | 
						|
</p>
 | 
						|
<p class='vspace'></p></td></tr></table>
 | 
						|
<p class='vspace'></p><p><a class='selflink' href='index.html'>Reference Home</a>
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><p><em>Corrections, suggestions, and new documentation should be posted to the <a class='urllink' href='http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?board=swbugs' rel='nofollow'>Forum</a>.</em>
 | 
						|
</p>
 | 
						|
<p class='vspace'></p><p>The text of the Arduino reference is licensed under a
 | 
						|
<a class='urllink' href='http://creativecommons.org/licenses/by-sa/3.0/' rel='nofollow'>Creative Commons Attribution-ShareAlike 3.0 License</a>.  Code samples in the reference are released into the public domain.
 | 
						|
</p>
 | 
						|
</div>
 | 
						|
 | 
						|
</div>
 | 
						|
<!--PageFooterFmt-->
 | 
						|
<div id="pagefooter">
 | 
						|
  <a href='#'>Edit Page</a> | <a href='#'>Page History</a> | <a href='#' target='_blank'>Printable View</a> | <a href='http://arduino.cc/en/Site/AllRecentChanges'>All Recent Site Changes</a>
 | 
						|
</div>
 | 
						|
<!--/PageFooterFmt-->
 | 
						|
</div>
 | 
						|
</body>
 | 
						|
</html>
 |