Sunday, February 14, 2010

Research into Project 1) LED

From the youtube video shown in our first lecture (and also included in the "Sites of Interest" section), it's clear that our first project will require us to manipulate the Arduino to power a small LED (Light Emitting Diode). The following is some useful information as to how this could be performed.

The following is taken from the Arduino site (http://www.arduino.cc/en/Tutorial/BlinkingLED).
"The "Hello World!" of Physical Computing.
The first program every programmer learns consists in writing enough code to make their code show the sentence "Hello World!" on a screen.
As a microcontroller, Arduino doesn't have any pre-established output devices. Willing to provide newcomers with some help while debugging programs, we propose the use of one of the board's pins plugging a LED that we will make blink indicating the right functionallity of the program.
We have added a 1K resistor to pin 13, what allows the immediate connection of a LED between that 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, trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of time).
Code
The example code is very simple, credits are to be found in the comments.

/* Blinking LED
* ------------
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino
* board because it has a resistor attached to it, needing only an LED
*
* Created 1 June 2005
* copyleft 2005 DojoDave
* http://arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
"

No comments:

Post a Comment