Arduino Language Document

Páginas: 71 (17561 palabras) Publicado: 7 de junio de 2012
L anguage Reference

The text of the Arduino reference is licensed under a Creative
Commons Attribution-ShareAlike 3.0 License. Code samples in the
reference are released into the public domain.
Arduino programs can be divided in three main parts: structure,
values (variables and constants), and functions.
INDEX

Structure
p5 setup()
p5 loop()
C ontrol Structures
p6 if
p7 if...else
p8 for
p10switch case
p11 while
p11 do... while
p12 break
p12 continue
p12 return
p13 goto
F urther Syntax
p14 ; (semicolon)
p14 {} (curly braces)
p16 // (single line comment)
p16 /* */ (multi-line comment)
p16 #define
p17 #include
A rithmetic Operators
p18 = (assignment operator)
p19 + (addition)
p19 - (subtraction)
p19 * (multiplication)
p19 / (division)
p20 % (modulo)
1

I NDEX continued
ComparisonOperators
p21 == (equal to)
p21 != (not equal to)
p21 < (less than)
p21 > (greater than)
p21 <= (less than or equal to)
p21 >= (greater than or equal to)
B oolean Operators
p22 && (and)
p22 || (or)
p22 ! (not)
P ointer Access Operators
p23 * dereference operator
p23 & reference operator
B itwise Operators
p23 & (bitwise and)
p24 | (bitwise or)
p26 ^ (bitwise xor)
p27 ~ (bitwise not)
p27 << (bitshiftleft)
p27 >> (bitshift right)
C ompound Operators
p29 ++ (increment)
p29 -- (decrement)
p30 += (compound addition)
p30 -= (compound subtraction)
p30 *= (compound multiplication)
p30 /= (compound division)
p30 &= (compound bitwise and)
p30 |= (compound bitwise or)

Variables
Constants
p34 HIGH | LOW
p34 INPUT | OUTPUT
p34 true | false
p36 integer constants
p37 floating point constants
D ata Types
p38void
p39 boolean
p39 char
p40 unsigned char
p40 byte
2

p40
p41
p42
p42
p42
p43
p44
p44
p47
p48

int
unsigned
word
long
unsigned
float
double
string String array

I NDEX continued
int
long
char array
object

C onversion
p49 char()
p50 byte()
p50 int()
p50 word()
p51 long()
p51 float()
V ariable Scope & Qualifiers
p52 variable scope
p53 static
p54 volatile
p55 const
U tilities
p56 sizeof()Functions
Digital I/O
p57 pinMode()
p58 digitalWrite()
p59 digitalRead()
A nalog I/O
p60 analogReference()
p61 analogRead()
p62 analogWrite() - PWM
A dvanced I/O
p64 tone()
p65 noTone()
p65 shiftOut()
p67 pulseIn()
T ime
p68 millis()
p69 micros()
p70 delay()
p71 delayMicroseconds()
3

I NDEX continued
Math
p72 min()
p72 max()
p73 abs()
p74 constrain()
p74 map()
p76 pow()
p76 sqrt()
T rigonometry
p76sin()
p77 cos()
p77 tan()
R andom Numbers
p77 randomSeed()
p78 random()
B its and Bytes
p79 lowByte()
p80 highByte()
p80 bitRead()
p80 bitWrite()
p81 bitSet()
p81 bitClear()
p82 bit()
E xternal Interrupts
p82 attachInterrupt()
p84 detachInterrupt()
I nterrupts
p84 interrupts()
p84 noInterrupts()
C ommunication
S erial
p86
p87
p87
p89
p90
p90
p92
p94

begin()
end()
available()
read()
flush()
print()println()
write()

4

S tructure
setup()
The setup() function is called when a sketch starts. Use it to
initialize variables, pin modes, start using libraries, etc. The
setup function will only run once, after each powerup or reset of
the Arduino board.
Example
int buttonPin = 3;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop()
{
// ...
}
loop()
After creating a setup()function, which initializes and sets the
initial values, the loop() function does precisely what its name
suggests, and loops consecutively, allowing your program to change
and respond. Use it to actively control the Arduino board.
Example
int buttonPin = 3;
// setup initializes serial and the button pin
void setup()
{
beginSerial(9600);
pinMode(buttonPin, INPUT);
}
// loop checks the button pineach time,
// and will send serial if it is pressed
void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite('H');
else
serialWrite('L');
delay(1000);
}
5

C ontrol Structures
if (conditional) and ==, !=, <, > (comparison operators)
if, which is used in conjunction with a comparison operator, tests
whether a certain condition has been reached, such as an input
being above a certain number....
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Que es arduino
  • Arduinos
  • ARDUINO
  • arduino
  • Arduino
  • Language
  • Language
  • Language

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS