© Royalty Free/CORBIS
© Royalty Free/Corbis


The Interface:

Screenshot0003.png

If you need Help with you program...

Hilite a command and then click on Help menu and select Reference:

Help


Common functions



Arduino Programming Notebook

Basic Sketch Structure

Arduino/Processing Language Comparison

The Arduino language (based on Wiring) is implemented in C, and therefore has some differences from the Processing language, which is based on Java.


Arrays
Arduino Processing
int bar[8];
bar[0] = 1;
int[] bar = new int[8];
bar[0] = 1;
int foo[] = { 0, 1, 2 }; int foo[] = { 0, 1, 2 };
or
int[] foo = { 0, 1, 2 };

Loops
Arduino Processing
int i;
for (i = 0; i < 5; i++) { ... }
for (int i = 0; i < 5; i++) { ... }

Printing
Arduino Processing
printString("hello world");
printNewline();
println("hello world");
int i = 5;
printInteger(i);
printNewline();
int i = 5;
println(i);
int i = 5;
printString("i = ");
printInteger(i);
printNewline();
int i = 5;
println("i = " + i);

Class Assignment:

  1. Read the following:

    There are 12 digital I/O (Input/Output) pins on the Arduino chip. These are the pins through which input and output devices may be connected. Depending on the code that is written, each pin may act as an input to read a device, or as an output to control a device. You will begin by using a very common and simple output device, the LED: Using an Active High LED, connect pin 8 to a 220 resistor, which connects to one side of an LED and connect the other side of the LED to ground:



    An LED is a diode, meaning electrons can flow in only one direction. In other words, polarity is important. The LED should have a flat side indicating the cathode or negative terminal. Also, the anode (positive terminal) generally has a longer lead than the cathode.
    led.jpg


    Here is the code to light the LED:
    /* blink an LED*/
    
    int LED1=8;
    
    void setup(){
       
        pinMode(LED1,OUTPUT);
        
    }
    
    void loop(){
        digitalWrite(LED1,HIGH);
        delay(500);
        digitalWrite(LED1,LOW);
        delay(500);
    }
    
    Code Explanation
    /* */ A comment
    digitalWrite(8,HIGH) defines the pin to be an output and sets it to a HIGH state, digital 1 or 5V
    digitalWrite(8,Low) defines the pin to be an output and sets it to a LOW state, digital 0 or 0V
    delay(500) instructs the chip to wait for the defined number of milliseconds (1/1000 seconds).

Modify the code so that the light is on for 50 milliseconds and off for 50 milliseconds. Before you run it, what do you think will happen?

Exercise II

Wire your board and code a program to perform the following sequence :
  1. LED1 on P8 ON, LED2 on P9 OFF

  2. Wait 2 seconds

  3. LED1 on P8 ON, LED2 on P9 ON

  4. Wait 1 second

  5. Both LEDs OFF

  6. Wait one-half second

  7. Repeat




Just so you know

There is a 1K resistor attached to pin 13, that allows the immediate connection of a LED between the pin and ground.

LEDs have polarity, which means they will only light up if you orient the legs properly. The long leg is typically positive, and should connect to pin 13. The short leg connects to GND; the bulb of the LED will also typically have a flat edge on this side. If the LED doesn't light up, reverse the legs (you won't hurt the LED if you plug it in backwards for a short period of time).

LedOnPin13.jpg