You are on page 1of 1

ATMega168 ATMega328 ATmega1280

Structure
void setup() void loop() Arduino Cheat Sheet V.02c Flash (2k for
boobtloader) 16kB 32kB 128kB
Mostly taken from the extended reference: SRAM
EEPROM
1kB
512B
2kB
1kB
8kB
4kB
Control Structures http://arduino.cc/en/Reference/Extended
if (x<5){ } else { } Gavin Smith – Robots and Dinosaurs, The Sydney Hackspace Duemilanove/
switch (myvar) { Nano/ Pro/
ProMini Mega
case 1: 14 + 6 analog
Constants Qualifiers External Interrupts
break; # of IO (Nano has 14+8) 54 + 16 analog
HIGH | LOW static // persists between calls attachInterrupt(interrupt, function, 0 - RX1 1 - TX1
case 2: 19 - RX2 18 - TX2
INPUT | OUTPUT volatile // use RAM (nice for ISR) [LOW,CHANGE,RISING,FALLING])
break; 0 - RX 17 - RX3 16 - TX3
true | false const // make read-only detachInterrupt(interrupt) Serial Pins 1 - TX 15 - RX4 14 - TX4
default:
143 // Decimal number PROGMEM // use flash interrupts() 2 - (Int 0) 2,3,21,20,19,18
}
0173 // Octal number noInterrupts() Ext Interrupts 3 - (Int 1) (IRQ0- IRQ5)
for (int i=0; i <= 255; i++){ } 5,6 - Timer 0
while (x<5){ } 0b11011111 //Binary Digital I/O Libraries: 9,10 - Timer 1

do { } while (x<5); 0x7B // Hex number pinMode(pin, [INPUT,OUTPUT]) PWM pins 3,11 - Timer 2 0-13
Serial. 10 - SS 53 - SS
continue; //Go to next in do/for/while loop 7U // Force unsigned digitalWrite(pin, value) 11 - MOSI 51 - MOSI
10L // Force long int digitalRead(pin) begin([300, 1200, 2400, 4800, 9600, 12 - MISO 50 - MISO
return x; // Or ‘return;’ for voids.
15UL // Force long unsigned //Write High to inputs to use pull-up res 14400, 19200, 28800, 38400, 57600, SPI 13 - SCK 52 - SCK
goto // considered harmful :-) Analog4 - SDA 20 - SDA
10.0 // Forces floating point 115200]) I2C Analog5 - SCK 21 - SCL
2.4e5 // 240000 Analog I/O end()
Further Syntax analogReference([DEFAULT,INTERNA int available()
// (single line comment) Data Types L,EXTERNAL]) int read()
/* (multi-line comment) */ void int analogRead(pin) //Call twice if flush()
#define DOZEN 12 //Not baker’s! boolean (0, 1, false, true) switching pins from high Z source. print()
#include <avr/pgmspace.h> char (e.g. ‘a’ -128 to 127) analogWrite(pin, value) // PWM println()
unsigned char (0 to 255) write()
byte (0 to 255) Advanced I/O EEPROM (#include <EEPROM.h>)
General Operators int (-32,768 to 32,767) byte read(intAddr)
tone(pin, freqhz)
= (assignment operator) unsigned int (0 to 65535) write(intAddr,myByte)
tone(pin, freqhz ,duration_ms)
+ (addition) - (subtraction) word (0 to 65535) noTone(pin) Servo (#include <Servo.h>)
* (multiplication) / (division) long (-2,147,483,648 to shiftOut(dataPin, clockPin, attach(pin , [min_uS, max_uS])
% (modulo) 2,147,483,647) [MSBFIRST,LSBFIRST], value) write(angle) // 0-180
== (equal to) != (not equal to) unsigned long (0 to 4,294,967,295) unsigned long pulseIn(pin, [HIGH,LOW]) writeMicroseconds(uS) //1000-2000,
< (less than) > (greater than) float (-3.4028235E+38 to
<= (less than or equal to) 1500 is midpoint
3.4028235E+38) Time
>= (greater than or equal to) read() // 0-180
double (currently same as float) unsigned long millis() // 50 days overflow.
&& (and) || (or) ! (not) attached() //Returns boolean
sizeof(myint) // returns 2 bytes unsigned long micros() // 70 min overflow detach()
delay(ms) From
Pointer Access SoftwareSerial(RxPin,TxPin) Arduino.CC
Strings delayMicroseconds(us)
& reference operator char S1[15]; // #include<SoftwareSerial.h>
* dereference operator char S2[8]={'a','r','d','u','i','n','o'}; Math begin(longSpeed) // up to 9600
char S3[8]={'a','r','d','u','i','n','o','\0'}; min(x, y) max(x, y) abs(x) char read() // blocks till data
//Included \0 null termination constrain(x, minval, maxval ) print(myData) or println(myData)
Bitwise Operators char S4[ ] = "arduino"; map(val, fromL, fromH, toL, toH)
& (bitwise and) | (bitwise or) Wire (#include <Wire.h>) // For I2C
char S5[8] = "arduino"; pow(base, exponent) sqrt(x)
^ (bitwise xor) ~ (bitwise not) begin() // Join as master
char S6[15] = "arduino"; sin(rad) cos(rad) tan(rad)
<< (bitshift left) >> (bitshift right) begin(addr) // Join as slave @ addr
Random Numbers requestFrom(address, count)
Arrays beginTransmission(addr) // Step 1
int myInts[6]; randomSeed(seed) // Long or int
Compound Operators long random(max) send(mybyte) // Step 2
++ (increment) -- (decrement) int myPins[] = {2, 4, 8, 3, 6}; send(char * mystring)
int mySensVals[6] = {2, 4, -8, 3, 2}; long random(min, max)
+= (compound addition) send(byte * data, size)
-= (compound subtraction) Bits and Bytes endTransmission() // Step 3
*= (compound multiplication) Conversion lowByte() highByte() byte available() // Num of bytes
/= (compound division) char() byte() bitRead(x,bitn) bitWrite(x,bitn,bit) byte receive() //Return next byte
&= (compound bitwise and) int() word() bitSet(x,bitn) bitClear(x,bitn) onReceive(handler)
Pics from Fritzing.Org under C.C. license
|= (compound bitwise or) long() float() bit(bitn) //bitn: 0-LSB 7-MSB onRequest(handler)

You might also like