Arduino Programming Notebook

March 29, 2019 | Author: Octavian Enache | Category: Variable (Computer Science), Subroutine, Control Flow, Array Data Type, Data Type
Share Embed Donate


Short Description

Download Arduino Programming Notebook...

Description

Arduino Programming Notebook  Written and compiled by Brian W. Evans

With information or inspiration taken from: http:www.arduino.cc http:www.wiring.org.co http:www.arduino.ccenBooklet!omePage http:cslibrary.stanford.edu"#"

  arduino  programming   notebook 

$ncluding material written by: Paul Badger  %assimo Ban&i !ernando Barrag'n (avid )uartielles *om $goe (aniel +olliffe *odd ,urt (avid %ellis and others

 brian w. evans

Published: -irst Edition August ##/ 0econd Edition 0eptember ##1

"c bao *his work is licensed under the )reative )ommons Attribution20hare Alike .3 4icense. *o view a copy of this license5 visit: http:creativecommons.orglicensesby2sa.3 6r send a letter to: )reative )ommons "/" 0econd 0treet5 0uite 7## 0an -rancisco5 )alifornia5 89"#35 0A

contents

structure structure

/

setup;<

/

loop;<

/

functions

1

=> curly braces

1

? semicolon

8

@ @ block comments

8

 line comments

8

variables variables

"#

variable declaration

"#

variable scope

""

datatypes  byte

"

int

"

long

"

float

"

arrays

"7

arithmetic arithmetic

"9

compound assignments

"9

comparison operators

"3

logical operators

"3

constants constants

"

truefalse

"

highlow

"

inputoutput

"

flow control if 

"/

if else

"1

for 

"8

while

#

do while

#

digital io  pin%ode;pin5 mode<

"

digitalCead;pin<



digitalWrite;pin5 value<



analog io analogCead;pin<

7

analogWrite;pin5 value<

7

delay;ms<

9

millis;<

9

min;D5 y<

9

maD;D5 y<

9

time

math

random random0eed;seed<

3

random;min5 maD<

3

0erial.begin;rate<



0erial.println;data<



serial

appendiD digital output

8

digital input

7#

high current output

7"

 pwm output

7

 potentiometer input

77

variable resistor input

79

servo output

73

 preface

*his notebook serves as a convenient5 easy to use programming reference for the command structure and basic syntaD of the Arduino microcontroller. *o keep it simple5 certain eDclusions were made that make this a beginners reference best used as a secondary source alongside other websites5 books5 workshops5 or classes. *his decision has lead to a slight emphasis on using the Arduino for standalone  purposes and5 for eDample5 eDcludes the more compleD uses of arrays or advanced forms of serial communication.

Beginning with the basic structure of ArduinoFs ) derived programming language5 this notebook continues on to describe the syntaD of the most common elements of the language and illustrates their usage with eDamples and code fragments. *his includes many functions of the core library followed by an appendiD with sample schematics and starter programs. *he overall format compliments 60ullivan and $goes Physical )omputing where possible. -or an introduction to the Arduino and interactive design5 refer to Ban&is Getting 0tarted with Arduino5 aka the Arduino Booklet. -or the brave few interested in the intricacies of programming in )5 ,ernighan a nd Citchies *he ) Programming 4anguage5 second edition5 as well as Prin& and )rawfords ) in a Nutshell5 provide some insight into the original programming syntaD. Above all else5 this notebook would not have been possible without the great community of makers and shear mass of original material to be found at the Arduino website5 playground5 and forum at http:www.arduino.cc.

structure *he basic structure of the Arduino programming language is fairly simple and runs in at least two parts. *hese two reHuired parts5 or functions5 enclose blocks of  statements. void setup;< =   statements? > void loop;< =   statements? > Where setup;< is the preparation5 loop;< is the eDecution. Both functions are reHuired for the program to work. *he setup function should follow the declaration of any variables at the very  beginning of the program. $t is the first function to run in the program5 is run only once5 and is used to set pin%ode or initiali&e serial communication. *he loop function follows neDt and includes the code to be eDecuted continuously I  reading inputs5 triggering outputs5 etc. *his function is the core of all Arduino  programs and does the bulk of the work.

setup;< *he setup;< function is called once when your program starts. se it to initiali&e pin modes5 or begin serial. $t must be included in a program even if there are no statements to run. void setup;< = pin%ode;pin5 6*P*
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF