User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Blinking LED!

Submitted by nick on Thu, 09/04/2008 - 16:37

 

Description

Use the Arduino to control a light emitting diode and make it blink.

 

Components Used

 

  • Light Emitting Diode (LED)
  • 220-ohm Resistor
  • Arduino board

 

Arduino Code

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

void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}

void loop() // run over and over again
{
blink(counter % 5 + 1);
delay(1000); // waits for a second
counter++;
}

void blink(int sec) {
digitalWrite(ledPin, HIGH);// sets the LED on
delay(1000 * sec); // waits for specified time
digitalWrite(ledPin, LOW); // sets the LED off
}