arduino processing

CODING CHEATSHEETS

CC:BY-SA, 22 Jan ‘14, R M Shearer

arduino processing

BASIC STRUCTURE

CC:BY-SA, 22 Jan ‘14, R M Shearer

code

; ; ; ; ; ; ; ; ; ;

// this is a comment /* this is a comment */ /* this is a comment */ // but this is not a comment

# define # include<>

void setup()

{} {} {}

void loop() or void draw ()
arduino processing

void yourownfunction()

arduino processing

CONDITIONALS (SIMPLE)

CC:BY-SA, 22 Jan ‘14, R M Shearer

if

() {}

if

() {}
else

while

() {}

{} { )
curly brackets for grouping code, eg: { x=0; y=x; }

(

normal brackets for function parameters, eg: if (10 < x < 50) { digitalWrite (13, HIGH);

}

arduino processing

CONDITIONALS (INTERMEDIATE)

CC:BY-SA, 22 Jan ‘14, R M Shearer

for

(*) {}

do

switch

(x){
case 1: break; case 2: break; case 3:

{}
while

* for will automatically increment a variable each time it loops example for declaration: for (int i=0; i <= 255; i++){

()

}

arduino processing

CONDITIONALS (ADVANCED)

CC:BY-SA, 22 Jan ‘14, R M Shearer

switch

(x){
case 1: case 2:

while or for

( ){
if

while or for

( ){
if

( ){
continue;

( ){
break;

} } }

}

default:

}

arduino processing

OPERATORS

CC:BY-SA, 22 Jan ‘14, R M Shearer

Arithmetic

Comparison

= + * / %

assignment operator: use to change a variable addition subtraction multiplication division modulo: gives the remainder after division

== != < > <= >= && || !

equal to: use to check a variable not equal to less than greater than less than or equal to greater than or equal to

Compound

Boolean and or not

++x x++ --

increment x then return new value of x return value of x then increment x decrement, as above