Physical Computing: Blink the LED

My first ITP-Blog will focus on a field that I have a lot of experience with over the past few years: Arduino. Though I’ve been dabbling with this microcontroller for about three years, I figured it would be beneficial to take this entry-level course and learn the coding from the ground up.

I’ve been posting Arduino-related projects here for quite some time without really explaining what the thing actually is or even what it looks like. Essentially, the Arduino microcontroller is a very basic processor that can take physical inputs (like switches and sensors) and control a variety of digital outputs (like lights and motors).

Arduino Uno

Arduino SMT Uno Board

The reason I love the Arduino so much is its versatility. It doesn’t have enough memory to process audio or video, but it can be used as a controller for cameras, motors, LED lights, MIDI instruments, light sensors, you name it. The possibilities are endless.

In Week 1, we were instructed to build a circuit that would blink an LED light. The code is relatively simple, and was reminiscent of an Arduino-based Christmas tree I built in 2009:

So I decided to get a bit creative and make a cascading LED pattern. Press the switch, and the LEDs light up in sequence. Release the switch, and they cascade in the other direction. Simple, straightforward, and fun.

LED Cascade from Mark Kleback on Vimeo.

Here’s the code:

void setup()
{
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(2, INPUT);
}
void loop()
{
if((digitalRead(2))==HIGH)
{
digitalWrite(7, HIGH);
delay(100);
digitalWrite(8, HIGH);
delay(100);
digitalWrite(9, HIGH);
delay(100);
digitalWrite(10, HIGH);
delay(100);
digitalWrite(11, HIGH);
delay(100);
digitalWrite(12, HIGH);
delay(100);
}
else
{
digitalWrite(12, LOW);
delay(100);
digitalWrite(11, LOW);
delay(100);
digitalWrite(10, LOW);
delay(100);
digitalWrite(9, LOW);
delay(100);
digitalWrite(8, LOW);
delay(100);
digitalWrite(7, LOW);
delay(100);
}
}

I’ll have more complicated Arduino projects in the next few weeks!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: