Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Arduino Cheat Sheet, Cheat Sheet of Programming Languages

Arduino language integer and Boolean operations , assignment, comments and main functions

Typology: Cheat Sheet

2020/2021

Uploaded on 04/23/2021

jacksonfive
jacksonfive 🇺🇸

4.4

(35)

280 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Arduino Cheatsheet
Values
int 3,-4
bool true ,false
Integer Operations
sum +3+4== 7
difference -6-8== -2
product *2*7== 14
quotient /7/3== 2
remainder %7%3== 1
Boolean Operations
equality == 4== 4
inequality < > 6>4
<= >= 5<= 7
not ! !(5<2)
!= 5!= 3
and && (4<5) && (7>3)
and/or || (4>9) || (4>2)
Assignment
initialisation int x=73;
int y;
updating x=37;
Abbreviations
x=x+1x++ or ++x
x=x-1x-- or --x
x=x+y x += y
x=x-y x -= y
x=x*y x *= y
x=x/y x /= y
x=x%y x %= y
Comments
// single line comment
/* ... */ multiple lines between the *s
If Blocks
Optionally run blocks of code depending on various
conditions. if is required, else if and else
blocks are optional but else should come last if
you use it.
if (a ge <13){
pr i nt (" C hi l d ") ;
}el se if (a ge <18){
pr i nt (" T ee n ag e r ") ;
}el se if (a ge <60){
pr i nt (" A du l t ") ;
}else {
pr i nt (" R e sp e ct e d Eld e r ") ;
}
For Loops
For loops run a block of code until a counter is
invalid. The following prints the numbers 0 to 9:
fo r (in t i=0;i<10;i=i+1){
pr i nt (i) ;
}
The first statement initialises the counter before
the loop runs. The second gives the condition for
the block to be run (when it is false , the loop
stops). The last says what happens in between it-
erations.
Common Functions
Digital pins can be in one of two modes, INPUT
if you want to check the voltage such as with a
switch, OUTPUT if you want to turn the pins on/off
such as with an LED. The voltages can be set to
HIGH (5 V) or LOW (0 V).
pinMode(pin,mode)
digitalRead(input_pin)
digitalWrite(output_pin,voltage)
delay(time)
The delay time is in milliseconds.
Main Functions
void se t up ( ) {
// code here runs when the
// Arduino starts
}
void loop( ) {
// this code runs again and
// again after setup until
// power is lost
}

Partial preview of the text

Download Arduino Cheat Sheet and more Cheat Sheet Programming Languages in PDF only on Docsity!

Arduino Cheatsheet

Values

int 3 , -

bool true , false

Integer Operations

sum + 3 + 4 == 7

difference - 6 - 8 == -

product * 2 * 7 == 14

quotient / 7 / 3 == 2

remainder % 7 % 3 == 1

Boolean Operations

equality == 4 == 4

inequality <=<^ >>=^ 6 > 45 <= 7

not !=!^ !(5 < 2)5 != 3

and && (4 < 5) && (7 > 3)

and/or || (4 > 9) || (4 > 2)

Assignment

initialisation int x = 73;

int y;

updating x = 37;

Abbreviations

x = x + 1 x++ or ++x

x = x - 1 x-- or --x

x = x + y x += y x = x - y x -= y x = x * y x *= y x = x / y x /= y x = x % y x %= y

Comments

// single line comment

/* ... */ multiple lines between the *s

If Blocks

Optionally run blocks of code depending on various

conditions. if is required, else if and else

blocks are optional but else should come last if

you use it.

if ( age < 1 3 ) { print ( " Child " ) ; } else if ( age < 1 8 ) { print ( " Teenager " ) ; } else if ( age < 6 0 ) { print ( " Adult " ) ; } else { print ( " Respected Elder " ) ; }

For Loops

For loops run a block of code until a counter is

invalid. The following prints the numbers 0 to 9:

for ( int i = 0 ; i < 1 0 ; i = i + 1 ) { print ( i ) ; }

The first statement initialises the counter before

the loop runs. The second gives the condition for

the block to be run (when it is false , the loop

stops). The last says what happens in between it-

erations.

Common Functions

Digital pins can be in one of two modes, INPUT

if you want to check the voltage such as with a

switch, OUTPUT if you want to turn the pins on/off

such as with an LED. The voltages can be set to

HIGH (5 V) or LOW (0 V).

pinMode(pin, mode) digitalRead(input_pin) digitalWrite(output_pin, voltage) delay(time)

The delay time is in milliseconds.

Main Functions

void setup ( ) { // code here runs when the // Arduino starts }

void loop ( ) { // this code runs again and // again after setup until // power is lost }