You are on page 1of 1

Structure Arduino Cheat Sheet V.

jfm01
void setup() void loop()
Mostly taken from the extended reference:
http://arduino.cc/en/Reference/Extended
Control Structures Gavin Smith Robots and Dinosaurs, The Sydney Hackspace
if (x<5){ } else { }
switch (myvar) {
Modificada por juanfelixmateos@gmail.com
case 1:
Constants Qualifiers External Interrupts
break;
HIGH | LOW static // persists between calls attachInterrupt(interrupt, function,
case 2:
INPUT | OUTPUT volatile // use RAM (nice for ISR) [LOW,CHANGE,RISING,FALLING])
break;
true | false const // make read-only detachInterrupt(interrupt)
default:
143 // Decimal number PROGMEM // use flash interrupts()
}
0173 // Octal number noInterrupts()
for (int i=0; i <= 255; i++){ }
while (x<5){ } 0b11011111 //Binary Digital I/O Libraries:
do { } while (x<5); 0x7B // Hex number pinMode(pin, [INPUT,
7U // Force unsigned INPUT_PULLUP,OUTPUT]) Serial.
continue; //Go to next in do/for/while loop
10L // Force long digitalWrite(pin, value) begin([300, 1200, 2400, 4800, 9600,
return x; // Or return; for voids.
15UL // Force long unsigned int digitalRead(pin) 14400, 19200, 28800, 38400, 57600,
goto // considered harmful :-) 115200])
10.0 // Forces floating point
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 bakers! 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