Programming Code of the Arduino

Obtaining Arduino and S4 Software

  1. Download the S4 Workspace from the S4 website http://s4.sonoma.edu/?page_id=167. Be sure to select the version that will work on your operating system.

  2. Extract the S4 Workspace (.zip) file that you download. Remember, the location where you extract this file will be where all of your files and resources for the S4 project will be located, including any programs you write yourself. It’s recommended you place this file on your desktop, or in a location where you can easily access it.

Basic Arduino Programming Commands and Punctuation Marks

The following commands and punctuation marks are commonly used in the Arduino computer language, called “Processing”.

Curly Brackets {}: Used to indicate the beginning and end of a function.

Semicolon ;: A semicolon is used to end a statement and separate elements of the code.

Setup (): Code written in the setup function will be executed once and only once when the program first starts.

Loop(): Code written in the loop function will be executed over and over again for as long as the device is running. This function is really the core of your program.

Void: This word often appears before the titles of functions such as setup and loop. In the Processing language, when you define a function, you must also define the type of variable that it will return. Using the void command simply means that the function will not return any type of value.

Comments: Any text written after double forward slashes // will be ignored. Comments are used to write notes to yourself as you write your program. These types of notes are very helpful when you need to troubleshoot your code, as they help you to recall the purpose of the code that you originally wrote.

#define: This command defines a variable to make our code cleaner and easier to write and read. It tells the Arduino to use the new value every time it sees the variable name. For example: #define (LED, 13) will write the number 13 every time it sees the variable name “LED” in the code.

PinMode(_,__): Tells the Arduino how to configure a certain pin. First in the parentheses comes the number of the pin you wish to specify followed by the mode of the pin. For example: pinMode(LED,OUTPUT) will tell Arduino to make the LED pin an output. The command pinMode is function and the information inside the parentheses are arguments.

DigitalWrite(_,_): This turns on or off any pin that is an output. The first value in the parentheses, specifies which pin; that the argument is followed by either “HIGH” (on), or “LOW” (off). For example: digitalWrite(LED,HIGH) will turn the LED on.

Delay(__): The delay function tells the Arduino to do nothing for a specified number of Milliseconds. For example: delay(1000) will tell the Arduino to wait and do nothing for 1000 milliseconds or 1 second.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s