Arduino Cheat Sheet
Arduino Cheat Sheet
Operators
General Operators = (assignment operator) + (add) - (subtract) * (multiply) / (divide) % (modulo) == (equal to) != (not equal to) < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) && (and) || (or) ! (not) Compound Operators ++ (increment) -- (decrement) += (compound addition) -= (compound substraction) *= (compound multiplication) /= (compound division) &= (compound bitwise and) |= (compound bitwise or) Bitwise Operators & (bitwise and) ^ (bitwise xor) << (shift left) Pin Input/Output
Built-in Functions
Digital I/O (pins: 0-13 A0-A5) pinMode(pin,[INPUT, OUTPUT]) int digitalread(pin) digitalWrite(pin, value) // Write HIGH to an input to // enable pull-up resistors Analog In (pins: 0-5) int analogRead(pin) analogReference( [DEFAULT, INTERNAL, EXTERNAL]) PWM Out (pins: 3 5 6 9 10 11) analogWrite(pin, value) Advanced I/O tone(pin, freqhz) tone(pin, freqhz, duration_ms) noTone(pin) shiftOut(dataPin, clockPin, [MSBFIRST,LSBFIRST], value) unsigned long pulseIn(pin, [HIGH,LOW]) Time unsigned long millis() // overflows at 50 days unsigned long micros() // overflows at 70 minutes delay(msec) delayMicroseconds(usec) Math min(x, y) max(x, y) abs(x) sin(rad) cos(rad) tan(rad) sqrt(x) pow(base, exponent) constrain(x, minval, maxval) map(val, fromL, fromH, toL, toH) Random Numbers randomSeed(seed) // long or int long random(max) long random(min, max) Bits and Bytes lowByte(x) highByte(x) bitRead(x, bitn) bitWrite(x, bitn, bit) bitSet(x, bitn) bitClear(x, bitn) bit(bitn) // bitn: 0=LSB 7=MSB Type Conversions char() byte() int() word() long() float() External Interrupts attachInterrupt(interrupt, func, [LOW, CHANGE, RISING, FALLING]) detachInterrupt(interrupt) interrupts() noInterrupts()
RESET
DIGITAL (PWM~)
L TX RX
ARDUINO UNO
ON
ICSP 1
(persists between calls) (in RAM (nice for ISR)) (make read only) (in flash)
7 ~6 ~5 4 ~3 2 TX1 RX0
int1 int0
SCL SDA
SDA SCL
Arrays int myInts[6]; // array of 6 ints int myPins[]={2, 4, 8, 3, 6}; int mySensVals[6]={2, 4, -8, 3, 2}; myInts[0]=42; // assigning first // index of myInts myInts[6]=12; // ERROR! Indexes // are 0 though 5
by Mark Liffiton
Adapted from: - Original by Gavin Smith - SVG version by Frederic Dufourg - Arduino board drawing original by Fritzing.org
POWER
ANALOG IN
A0 A1 A2 A3 A4 A5