0% found this document useful (0 votes)
11 views1 page

Arduino Aide mémoire

The document is an Arduino Cheat Sheet that outlines the basic structure, flow control, operators, built-in functions, and libraries used in Arduino programming. It includes examples of program structure, control structures, data types, and various functions for digital and analog I/O, as well as communication protocols. Additionally, it provides information on arrays, pointers, and constants relevant to Arduino development.

Uploaded by

houda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Arduino Aide mémoire

The document is an Arduino Cheat Sheet that outlines the basic structure, flow control, operators, built-in functions, and libraries used in Arduino programming. It includes examples of program structure, control structures, data types, and various functions for digital and analog I/O, as well as communication protocols. Additionally, it provides information on arrays, pointers, and constants relevant to Arduino development.

Uploaded by

houda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Most information from the Arduino Language Reference:

Arduino Cheat Sheet http://arduino.cc/en/Reference/HomePage

Structure & Flow Operators Built-in Functions Libraries


Basic Program Structure General Operators Digital I/O Math Serial (communicate with PC or via RX/TX)
void setup() { = (assignment operator) pinMode(pin,[INPUT, OUTPUT]) min(x, y) max(x, y) abs(x) begin(long Speed) // set bits/sec
// runs once when sketch starts + (add) - (subtract) digitalWrite(pin, value) sin(rad) cos(rad) tan(rad) end()
} * (multiply) / (divide) int digitalread(pin) sqrt(x) pow(base, exponent) int available()
byte read()
void loop() { % (modulo) // Write HIGH to inputs to use constrain(x, minval, maxval)
byte peek()
// runs repeatedly == (equal to) != (not equal to) // pull-up resistors map(val, fromL, fromH, toL, toH) flush()
} < (less than) > (greater than) print(myData)
<= (less than or equal to) Analog I/O Random Numbers println(myData)
Control Structures >= (greater than or equal to) randomSeed(seed) // long or int write(myBytes)
analogReference([DEFAULT, flush()
if (x < 5) { ... } else { ... } && (and) || (or) ! (not) long random(max)
INTERNAL, EXTERNAL])
while (x < 5) { ... } int analogRead(pin) long random(min, max)
do { ... } while ( x < 5); Compound Operators EEPROM (#include <EEPROM.h>)
// Call twice if switching pin
for (int i = 0; i < 10; i++) { ... } ++ (increment) // from a high-Z source byte read(intAddr)
Bits and Bytes
break; // exit a loop immediately -- (decrement) analogWrite(pin, value) // PWM write(intAddr, myByte)
lowByte(x) highByte(x)
continue; // go to next iteration += (compound addition) bitRead(x, bitn)
switch (myVar) { -= (compound substraction) Servo (#include <Servo.h>)
Advanced I/O bitWrite(x, bitn, bit)
case 1: *= (compound multiplication) attach(pin, [min_uS, max_uS])
tone(pin, freqhz) bitSet(x, bitn)
... /= (compound division)
tone(pin, freqhz, duration_ms) bitClear(x, bitn) write(angle) // 0, 180
break; &= (compound bitwise and)
noTone(pin) bit(bitn) // bitn: 0=LSB 7=MSB writeMicroseconds(uS)
case 2: |= (compound bitwise or)
shiftOut(dataPin, clockPin, // 1000-2000; 1500 is midpoint
...
[MSBFIRST,LSBFIRST], value) Conversions read() // 0 - 180
break;
Bitwise Operators unsigned long pulseIn(pin, attached() // returns boolean
default: char() byte()
[HIGH,LOW]) detach()
... & (bitwise and) | (bitwise or) int() word()
} ^ (bitwise xor) ~ (bitwise not) long() float()
return x; // or "return;" for voids << (shift left) >> (shift right) SoftwareSerial (serial comm. on any pins)
Time
(#include <softwareSerial.h>)
unsigned long millis() External Interrupts
SoftwareSerial(rxPin, txPin)
// overflow at 50 days attachInterrupt(interrupt, func,
// select rx and tx pins
unsigned long micros() [LOW, CHANGE, RISING, FALLING])
Variables, Arrays, and Data // overflow at 70 minutes detachInterrupt(interrupt)
begin(long Speed) // up to 9600
char read() // blocks till data
delay(ms) interrupts()
Data types Constants print(myData)
delayMicroseconds(us) noInterrupts()
void HIGH | LOW println(myData)
boolean (0, 1, true, false) INPUT | OUTPUT
char (e.g. 'a' -128 to 127) true | false Wire (I²C comm.) (#include <Wire.h>)
int (-32768 to 32767) 143 // Decimal begin() // join a master
long (-2147483648 to 2147483647) 0173 // Octal (leading 0) begin(addr) // join a slave @ addr
unsigned char (0 to 255) 0b11011111 // Binary requestFrom(address, count)

2
GND
13
12
~11
~10
~9

~6
~5

~3
AREF

TX→1
RX←0
byte (0 to 255) 0x7B // Hex (hexadecimal) beginTransmission(addr) // Step 1
unsigned int (0 to 65535) 7U // force unsigned
DIGITAL (PWM~)
send(myByte) // Step 2
word (0 to 65535) 10L // force long L send(char * mystring)
unsigned long (0 to 4294967295) 15UL // force long unsigned send(byte * data, size)
float
double
(-3.4028e+38 to 3.4028e+38)
(currently same as float)
10.0
2.4e5
// force floating point
// 240000
TX
RX
ARDUINO ON endTransmission() // Step 3
byte available() // Num of bytes

1
byte receive() // Return next byte
Qualifiers onReceive(handler)
Pointer Access

ICSP
static // persists between calls onRequest(handler)
& (reference: get a pointer)
volatile // use RAM (nice for ISR)
* (dereference: follow a pointer)
const // make read only RESET

WWW.ARDUINO.CC
PROGMEM // Use flash
Strings by Mark Liffiton
Arrays char S1[8] =
int myInts[6]; // array of 6 ints {'A','r','d','u','i','n','o'};
int myPins[]={2, 4, 8, 3, 6}; // unterminated string; may crash
Adapted from:
int mySensVals[6]={2, 4, -8, 3, 2}; char S2[8] = POWER ANALOG IN - Original by Gavin Smith
RESET
3.3V

myInts[0]=42; // assigning first {'A','r','d','u','i','n','o','\0'}; - SVG version by Frederic Dufourg


GND
GND
Vin
5V

A0
A1
A2
A3
A4
A5
// index of myInts // includes \0 null termination
myInts[6]=12; // ERROR! Indexes char S3[]="arduino";
- Arduino board drawing
// are 0 though 5 char S4[8]="arduino"; original by Fritzing.org

You might also like