Language Reference Structure •
void setup()
•
void loop()
Control Structures
Functions Digital I/O •
pinMode(pin, mode)
•
digitalWrite(pin, value)
•
int digitalRead(pin)
•
if
•
if...else
•
for
•
int analogRead(pin)
•
switch case
•
analogWrite(pin, value) - PWM
•
while
•
do... while
•
break
•
continue
•
return
Further Syntax •
; (semicolon)
•
{} (curly braces)
•
// (single line comment)
•
/* */ (multi-line comment)
Arithmetic Operators •
= (assignment)
•
+ (addition)
•
- (subtraction)
•
* (multiplication)
•
/ (division)
•
% (modulo)
Comparison Operators •
== (equal to)
•
!= (not equal to)
•
< (less than)
•
> (greater than)
•
<= (less than or equal to)
•
>= (greater than or equal to)
Analog I/O
Advanced I/O •
shiftOut(dataPin, clockPin, bitOrder, value)
•
unsigned long pulseIn(pin, value)
Time •
unsigned long millis()
•
unsigned long micros()
•
delay(ms)
•
delayMicroseconds(us)
Math •
min(x, y)
•
max(x, y)
•
abs(x)
•
constrain(x, a, b)
•
map(value, fromLow, fromHigh, toLow, toHigh)
•
pow(base, exponent)
•
sq(x)
•
sqrt(x)
Trigonometry •
sin(rad)
•
cos(rad)
Boolean Operators
•
tan(rad)
•
&& (and)
•
|| (or)
•
randomSeed(seed)
•
! (not)
•
long random(max)
•
long random(min, max)
Compound Operators
Random Numbers
•
++ (increment)
•
-- (decrement)
•
+= (compound addition)
•
-= (compound subtraction)
•
*= (compound multiplication)
•
char()
•
/= (compound division)
•
byte()
Variables
•
int()
Variables are expressions that you can use in programs to store values, such as a sensor reading from an analog pin.
•
long()
•
float()
Data Types
Communication •
Serial
Conversion
Constants
Variables can have various types, which are Constants are particular values with specific described below. meanings. • boolean • HIGH | LOW •
char
•
INPUT | OUTPUT
•
byte
•
true | false
•
int
•
Integer Constants
•
unsigned int
•
long
•
unsigned long
•
float
•
double
•
string
•
array
•
void