Arduino-Cheat-Sheet.pdf

(1201 KB) Pobierz
ARDUINO CHEAT SHEET
J
EROEN
D
OGGEN
, AP U
NIVERSITY
C
OLLEGE
A
NTWERP
Structure
void
setup()
void
loop()
Constants
HIGH, LOW
INPUT, OUTPUT
true, false
53 : Decimal
B11010101 : Binary
0x5BA4 : Hexadecimal
Interrupts
attachInterrupt(interrupt,
function, type)
detachInterrupt(interrupt)
boolean(interrupt)
interrupts()
noInterrupts()
I/O Pins
# of IO
Serial Pins 3
Interrupts
PWM Pins
SPI
(SS, MOSI, MISO, SCK)
I2C
(SDA, SCK)
Uno
14 + 6
0 - RX, 1 -TX
2,3
5,6 - 9,10 - 3,11
10→ 13
A4, A5
Mega
54 + 11
RX1
RX4
2,3,18,19,20,21
0
13
50→ 53
20,21
Control Structures
if(x<5){}
for(int
i = 0; i < 255; i++ ){}
while((x
< 6 ){}
Advanced I/O
Data Types
void
boolean
char
unsigned char
int
unsigned int
long
float
sizeof
(myint)
0, 1, false, true
e.g. ’a’ -128
127
0
255
-32.768
32.767
0
65535
-2.147.483.648
2.147.483.647
-3,4028235E+38
3.402835E+38
returns 2 bytes
tone(pin,
freqhz)
tone(pin,
freqhz, duration_ms)
noTone(pin)
shiftOut
(dataPin, clockPin, how, value)
unsigned long
pulseIn(pin,
[HIGH,LOW])
Analog I/O
analogReference(EXTERNAL,
INTERNAL)
analogRead(pin)
analogWrite(pin,
value)
Further Syntax
//
Single line comment
/
..
/
Multi line comment
#define ANSWER 42
#include <myLib.h>
Time
unsigned long
millis()
unsigned long
micros()
delay(ms)
delayMicroseconds(us)
50 days overflow
70 min overflow
Digital I/O
pinMode(pin,[INPUT,OUTPUT])
digitalRead(pin)
digitalWrite(pin,
value)
General Operators
=
+,
∗,
/
%
==
!=
<
<=
assignment
addition, substraction
multiplication, division
modulo
equal to
not equal to
less than
less than or equal to
Arrays
int myInts[6];
int myPins[]=2,4,8,5,6;
int myVals[6]=2,-4,9,3,5;
Math
min(x,y) max(x,y) abs(x)
sin(rad) cos(rad) tan(rad)
pow(base,
exponent)
map(val,
fromL, fromH, toL, toH)
constrain(val,
fromL, toH)
Serial Communication
Serial.begin(speed)
Serial.print(“Text”)
Serial.println(“Text”)
Strings
char S1[15];
char S2[8]=’A’,’r’,’d’,’u’,’i’,’n’,’o’;
char S3[8]=’A’,’r’,’d’,’u’,’i’,’n’,’o’,’\0’;
char S4[]=“Arduino”;
char S5[8] = “Arduino”;
char S6[15] = “Arduino”;
Websites
forum.arduino.cc
playground.arduino.cc
arduino.cc/en/Reference
Pointer Access
&
reference operator
dereference operator
Pseudo Random Numbers
randomSeed(seed)
long
random(max)
long
random(min,
max)
Bitwise Operators
&
|
bitwise AND
bitwise OR
bitwise XOR
bitwise NOT
Arduino Uno Board
Conversion
char()
byte()
int()
word()
long()
float()
ATmega328 Pinout
Compound Operators
++
−−
+=
&=
Increment
Decrement
Compound addition
Compound bitwise AND
Qualifiers
static
volatile
const
PROGMEM
Persist between calls
Use RAM (nice for ISR)
Mark read-only
Use flash memory
Zgłoś jeśli naruszono regulamin