Saturday, May 15, 2010

Hello World: Starting out with Arduino

I recently purchased an Arduino Duemilanove from http://www.adafruit.com/.  As my "Hello World" beginning code I modified a sketch to signal SOS in Morse Code from a blinking LED.  A picture of the Italian made open hardware micro controller and my code are below.

/* SOS Blink

Blinks LED in Morse Code "SOS", repeatedly.

The circuit:
* LED connected from digital pin 13 to ground.

Created 5.15.10
By Glenn Langton
http://glennlangton.blogspot.com

based on an orginal by H. Barragan for the Wiring i/o board

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,

void loop()
{
/* Code S */
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(300); // wait for 3/10 second
/* Code O */
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for 1 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for 1 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for 1 second
digitalWrite(ledPin, LOW); // set the LED off
delay(300); // wait for 3/10 second
/* Code S */
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(300); // wait for 3/10 second

/*Pause 2 seconds for next SOS sequence*/
delay(2000);
}

0 comments:

Post a Comment