27
Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 1 智智智智智智智智智智 (1/3) Arduino Programming Language Chin-Shiuh Shieh ( 智智智 ) http://bit.kuas.edu.tw/~csshieh Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan

智慧電子應用設計導論 (1/3) Arduino Programming Language

Embed Size (px)

DESCRIPTION

智慧電子應用設計導論 (1/3) Arduino Programming Language. Chin-Shiuh Shieh ( 謝欽旭 ) http://bit.kuas.edu.tw/~csshieh Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan. Arduino Programming Language. Arduino – Tutorials http://arduino.cc/en/Tutorial/HomePage - PowerPoint PPT Presentation

Citation preview

Page 1: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 1

智慧電子應用設計導論 (1/3)Arduino Programming

Language

Chin-Shiuh Shieh (謝欽旭 )http://bit.kuas.edu.tw/~csshieh

Department of Electronic Engineering

National Kaohsiung University of Applied Sciences, Taiwan

Page 2: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 2

Arduino Programming Language

• Arduino – Tutorials– http://arduino.cc/en/Tutorial/HomePage

• Arduino - Reference – http://arduino.cc/en/Reference/HomePage

• Arduino – Libraries– http://arduino.cc/en/Reference/Libraries

Page 3: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 3

Structure

• setup()

• loop()

Page 4: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 4

Structure - Control Structures

• if• if...else• for• switch case• while• do... while• break• continue• return• goto

Page 5: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 5

Structure - Further Syntax

• ; (semicolon)

• {} (curly braces)

• // (single line comment)

• /* */ (multi-line comment)

• #define

• #include

Page 6: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 6

Structure - Arithmetic Operators

• = (assignment operator)

• + (addition)

• - (subtraction)

• * (multiplication)

• / (division)

• % (modulo)

Page 7: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 7

Structure - Comparison Operators

• == (equal to)

• != (not equal to)

• < (less than)

• > (greater than)

• <= (less than or equal to)

• >= (greater than or equal to)

Page 8: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 8

Structure - Boolean Operators

• && (and)

• || (or)

• ! (not)

Page 9: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 9

Structure - Pointer Access Operators

• * dereference operator

• & reference operator

Page 10: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 10

Structure - Bitwise Operators

• & (bitwise and)

• | (bitwise or)

• ^ (bitwise xor)

• ~ (bitwise not)

• << (bitshift left)

• >> (bitshift right)

Page 11: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 11

Structure - Compound Operators

• ++ (increment)• -- (decrement)• += (compound addition)• -= (compound subtraction)• *= (compound multiplication)• /= (compound division)• &= (compound bitwise and)• |= (compound bitwise or)

Page 12: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 12

Variables - Constants

• HIGH | LOW

• INPUT | OUTPUT| INPUT_PULLUP

• true | false

• integer constants

• floating point constants

Page 13: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 13

Variables - Data Types• void• boolean• char• unsigned char• byte• int• unsigned int• word• long• unsigned long• float• double• string - char array• String - object• array

Page 14: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 14

Variables - Conversion

• char()

• byte()

• int()

• word()

• long()

• float()

Page 15: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 15

Variables - Variable Scope & Qualifiers

• variable scope

• static

• volatile

• const

Page 16: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 16

Variables - Utilities

• sizeof()

Page 17: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 17

Functions - Digital I/O

• pinMode()

• digitalWrite()

• digitalRead()

Page 18: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 18

Functions - Analog I/O

• analogReference()

• analogRead()

• analogWrite() - PWM

Page 19: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 19

Functions - Advanced I/O

• tone()

• noTone()

• shiftOut()

• shiftIn()

• pulseIn()

• pulseIn(2,HIGH);

Page 20: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 20

Functions - Time

• millis()

• micros()

• delay()

• delayMicroseconds()

Page 21: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 21

Functions - Math

• min()

• max()

• abs()

• constrain()

• map()

• pow()

• sqrt()

Page 22: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 22

Functions - Trigonometry

• sin()

• cos()

• tan()

Page 23: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 23

Functions - Random Numbers

• randomSeed()

• random()

Page 24: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 24

Functions - Bits and Bytes

• lowByte()

• highByte()

• bitRead()

• bitWrite()

• bitSet()

• bitClear()

• bit()

Page 25: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 25

Functions - External Interrupts

• attachInterrupt()

• detachInterrupt()

Page 26: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 26

Functions - Interrupts

• interrupts()

• noInterrupts()

Page 27: 智慧電子應用設計導論 (1/3) Arduino Programming Language

Autumn, 2014 C.-S. Shieh, EC, KUAS, Taiwan 27

Functions - Communication

• Serial

• Stream