Thursday, January 13, 2011

Arduino Project 1 - 3 Blinking LEDs



/*
Blink - 3 LEDs
Turns on 3 LEDs in succession
This example code is in the public domain.
*/
void setup() {
// initialize the digital pins as outputs.
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // Green LED on
delay(100); // wait
digitalWrite(13, LOW); // Green LED off
delay(500); // wait
digitalWrite(7, HIGH); // Blue LED on
delay(200); // wait
digitalWrite(7, LOW); // Blue LED off
delay(50); // wait
digitalWrite(2, HIGH); // Red LED on
delay(75); // wait
digitalWrite(2, LOW); // Red LED off
delay(200); // wait
digitalWrite(7, HIGH);
delay(100);
digitalWrite(7, LOW);
delay(350);
}

This is the first Arduino project I've created, based on the first project in the book Getting Started with Arduino. The first project in this book has you create a single blinking LED, but I had 3 LEDs to try out so I added the lines for the additional lights.

The Arduino is a device I was fortunate to hear about last year. It has become even more popular since then, and will probably become even more popular thanks to a recent documentary about the device, available at Vimeo.

Arduino The Documentary (2010) English HD from gnd on Vimeo.


What makes this device special is that it allows for the easy prototyping of electronic devices. This means that never before has it been easier to take your old electronics and turn them into a new machine, controlled by a program you write yourself. There is also a growing resource of other Open Source projects available, which can then be shared worldwide.

The best part is, the software and most of the learning materials are all available for free at:
http://www.arduino.cc

The Arduino board itself can be bought at:
http://www.sparkfun.com
30 Arduino Projects for the Evil Genius

1 comment:

  1. I did something like that here is the code that i made.



    /*This project makes 3 LEDs turn on one after the other, then repeats backwards
    turning them off one after the other. Once the button is pushed it takes
    a total of 3.5 seconds for all of the lights to illuminate.
    If the number signs below were considered LEDs then the first one would light
    the second one then the third one. Then it would to the same thing except the
    opposite. so the third led would turn off then the second woud turn off
    then the first one would turn off. At the end all three should blink three
    times.

    led 1 led2 led3
    # # #
    */

    int led1 = 13;
    int led2 = 12;
    int led3 = 11;
    int button = 2;
    int buttonState = 0;

    void setup()
    {
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    pinMode(button, INPUT);
    }

    void loop() {
    digitalWrite(led1, HIGH);
    delay(300);
    digitalWrite(led1, LOW);
    delay(400);
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    delay(200);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    delay(200);
    digitalWrite(led1, HIGH);
    delay(500);
    digitalWrite(led2, HIGH);
    delay(500);
    digitalWrite(led3, HIGH);
    delay(1000);
    digitalWrite(led3, LOW);
    delay(500);
    digitalWrite(led2, LOW);
    delay(500);
    digitalWrite(led1, LOW);
    delay(500);
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    delay(300);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    delay(300);
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    delay(300);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    delay(300);
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    delay(300);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    }

    ReplyDelete