75

Arduino introduction

Embed Size (px)

Citation preview

Page 1: Arduino introduction
Page 2: Arduino introduction
Page 3: Arduino introduction
Page 4: Arduino introduction
Page 5: Arduino introduction
Page 6: Arduino introduction
Page 7: Arduino introduction

Digital Signal

Processors

General-purpose Microprocessors Microcontrollers

Microprocessors

8086, Pentium I-IV, Core-duo, Atom, Sparc,..

8051, PIC, ATMEGA, AVR,.. TMS320XX

AD21XX,…

Type of Microprocessors

Page 8: Arduino introduction
Page 9: Arduino introduction
Page 10: Arduino introduction

WHAT IS ARDUINO?

Page 11: Arduino introduction

Why invented the Arduino boards ?

Page 12: Arduino introduction
Page 13: Arduino introduction
Page 14: Arduino introduction
Page 15: Arduino introduction
Page 16: Arduino introduction
Page 17: Arduino introduction
Page 18: Arduino introduction
Page 19: Arduino introduction
Page 20: Arduino introduction
Page 21: Arduino introduction

Arduino shield

Page 22: Arduino introduction

GSM shield Arduino

Page 23: Arduino introduction

GPS shield Arduino

Page 24: Arduino introduction
Page 25: Arduino introduction
Page 26: Arduino introduction
Page 27: Arduino introduction
Page 28: Arduino introduction
Page 29: Arduino introduction
Page 30: Arduino introduction
Page 31: Arduino introduction
Page 32: Arduino introduction
Page 33: Arduino introduction

Programming

Page 34: Arduino introduction
Page 35: Arduino introduction
Page 36: Arduino introduction

Sketches

Page 37: Arduino introduction
Page 38: Arduino introduction

??

? ?

? ??

??

?

Page 39: Arduino introduction

Microcontroller

Arduino c

Page 40: Arduino introduction

C programming

Page 41: Arduino introduction

Important notes { } curly braces

Curly braces (also referred to as just "braces" or "curly brackets") define the beginning and end of

function blocks and statement blocks such as the void loop() function and the for and if statements.

Void Loop(){ Statements;}

Page 42: Arduino introduction

; semicolon A semicolon must be used to end a statement and separate

elements of the program. A semicolon is also used to separate elements in a for loop.

int x = 13; // declares variable 'x' as the integer 13

/*… */ block comments Block comments, or multi-line comments, are areas of text ignored

by the program and are used for large text descriptions of code or comments that help others understand parts of the program. They begin with /* and end with */ and can span multiple lines.

/* this is an enclosed block comment don’t forget the closing comment - they have to be balanced! */

Page 43: Arduino introduction

// line comments Single line comments begin with // and end with the next

line of code. Like block comments, they are ignored by the program and take no memory

space.

// this is a single line comment

Single line comments are often used after a valid statement to provide more information about what the statement

accomplishes or to provide a future reminder.

Page 44: Arduino introduction
Page 45: Arduino introduction

boolean (0, 1, false, true) char (e.g. ‘a’ -128 to 127) unsigned char (0 to 255)

byte (0 to 255) int (-32,768 to 32,767) unsigned int (0 to 65535)

word (0 to 65535) long (-2,147,483,648 to 2,147,483,648

unsigned long (0 to 4,294,967,295)

float -(3.4028235E+38 to

3.4028235E+38)double (currently same

as float)sizeof(myint) // returns 2

bytes

Page 46: Arduino introduction
Page 47: Arduino introduction

General Operators= (assignment operator)

+ (addition) - (subtraction)

(multiplication) */ (division)% (modulo)

== (equal to) != (not equal to)< (less than) > (greater than)

<= (less than or equal to)>= (greater than or equal to)

&& (and) || (or) ! (not)

Page 48: Arduino introduction

x ++ // same as x = x + 1, or increments x by +1

x -- // same as x = x - 1, or decrements x by -1

x += y // same as x = x + y, or increments x by +y

x -= y // same as x = x - y, or decrements x by -y

x *= y // same as x = x * y, or multiplies x by y

x /= y // same as x = x / y, or divides x by y

Page 49: Arduino introduction

Arduino c

C programming

Arduino c

C programming

Page 50: Arduino introduction
Page 51: Arduino introduction
Page 52: Arduino introduction

Lecture 2

Page 53: Arduino introduction

Microcontroller

Arduino c

Page 54: Arduino introduction

C programming

Page 55: Arduino introduction

Important notes { } curly braces

Define the beginning and end of function blocks and statement blocks such as the void loop() function and the for and if statements.

Void Loop(){ Statement;Statement;

}

Page 56: Arduino introduction

; semicolon A semicolon must be used to end a statement and separate

elements of the program. A semicolon is also used to separate elements in a for loop.

int x = 13; // declares variable 'x' as the integer 13

/*… */ block comments Block comments, or multi-line comments, are areas of text ignored

by the program and are used for large text descriptions of code or comments that help others understand parts of the program. They begin with /* and end with */ and can span multiple lines.

/* this is an enclosed block comment don’t forget the closing comment - they have to be balanced! */

Page 57: Arduino introduction

// line comments Single line comments begin with // and end with the next

line of code. Like block comments, they are ignored by the program and take no memory

space.

// this is a single line comment

Single line comments are often used after a valid statement to provide more information about what the statement

accomplishes or to provide a future reminder.

Page 58: Arduino introduction
Page 59: Arduino introduction

boolean (0, 1, false, true) char (e.g. ‘a’ -128 to 127) unsigned char (0 to 255)

byte (0 to 255) int (-32,768 to 32,767) unsigned int (0 to 65535)

word (0 to 65535) long (-2,147,483,648 to 2,147,483,648

unsigned long (0 to 4,294,967,295)

float -(3.4028235E+38 to

3.4028235E+38)double (currently same

as float)sizeof(myint) // returns 2

bytes

Page 60: Arduino introduction

General Operators= (assignment operator)

+ (addition) - (subtraction)

(multiplication) */ (division)% (modulo)

== (equal to) != (not equal to)< (less than) > (greater than)

<= (less than or equal to)>= (greater than or equal to)

&& (and) || (or) ! (not)

Page 61: Arduino introduction

Code Structures

Page 62: Arduino introduction
Page 63: Arduino introduction

Control statements • If statement • Switch case statement • While statement • Do …. While statement • For statement

Page 64: Arduino introduction

• If statement • Switch case statement

• While statement • Do …. While statement • For statement

Page 65: Arduino introduction

If statement One way selection

Example

If (score >= 60) grade = ‘P’ ;else grade = ‘F’ ;

Example

Two way selection

Multiple selections

Example

Page 66: Arduino introduction

Important notes { } curly braces

Define the beginning and end of function blocks and statement blocks such as the void loop() function and the for and if statements.

Void Loop(){ Statement;Statement;

}

Page 67: Arduino introduction

Compound statement (block of statements):

if (age > 18){

cout << "Eligible to vote." << endl;cout << "No longer a minor." << endl;

} else{

cout << "Not eligible to vote." << endl;cout << "Still a minor." << endl;

}

Example

Page 68: Arduino introduction

Switch case statement switch structure

Example

Page 69: Arduino introduction

• If statement • Switch case statement

• While statement • Do …. While statement • For statement

Page 70: Arduino introduction

Example

• while Looping (Repetition) • do…while Looping (Repetition) Structure (continued)

Example

Page 71: Arduino introduction
Page 72: Arduino introduction

For statement

Page 73: Arduino introduction

Infinite loop using while and for

for (;;)cout << "Hello" << endl;

While(1){cout << "Hello" << endl;}

Page 74: Arduino introduction

Arduino c

C programming

Arduino c

C programming

Page 75: Arduino introduction