Although most of this code is universal, it is intended for use on Arduino Uno R3. And remember, the official reference is always the best and most accurate resource.
Other great resources:
Anatomy of a Sketch
Anatomy of a Function
- Function – A logical block of code that has a name and can be executed from somewhere else in the program. The function may do something, or it may return something. (more info)
- Return – If a function returns something, then it outputs a value.
- Return Type – Defines what type of variable the function returns. If it returns nothing, then you put “void”.
- Function Name – Every function needs a unique name. The name should be in camelCase (i.e. “My Function” should be written as “myFunction”).
- Arguments – Sometimes it’s useful to send information to a program. This can be done as arguments.
Comments are a way for a programmer to annotate their code.
Working w/ Variables
Variables are how programmers store, hold, and manipulate date.
Loops & Iteration
Here are some examples of different ways we could make a program count for us using loops.
Tools like if/then/else, while, and for depend on using conditionals. A conditional is an expression that outputs true or false.
|Comparison Operators||Boolean Operators|
An Example – serial_repeater
This is an example is called serial_repater and is provided with the MySerial Library.
Installing Libraries Off Network (Personal Laptop or at Home)
- Download the appropriate library as a .zip file (go to File > Download). Libraries are posted here.
- Open it to view the contents. It should contain a folder.
- Move (or copy and paste) the folder to this exact directory: \My Documents\Arduino\libraries
- If it asks, choose to replace the existing folder.
Installing Libraries On Network (at school)
- Open the Arduino application.
- Navigate to File > Preferences
- Set the Sketchbook Location as: T:\Swaaley-Strong\Arduino
- Close then re-open the Arduino Application
Using Libraries & Library Examples
- When in the Arduino IDE, click Sketch > Import Library.
- To find an example of a sketch that uses this library, click File > Examples