Week2 Assignment : Blink LED

I’ve learned aboout the Arduino. I thought the program will be very difficult, but it wasn’t.

So intersting! LEDs are really cute. Feels like I’m a scientist!

 

 

1. Blinking one LED.

CODE>>>

int led0 = 2;

void setup() {

pinMode(led0, OUTPUT); }

void loop() {

digitalWrite(led0, HIGH);

delay(250);

digitalWrite(led0, LOW);

delay(250); }

 

 

2. Blinking many LEDs.

CODE>>

int led0 = 2;

int led1 = 3;

int led2 = 4;

int led3 = 5;

int led4 = 6;

void setup() {

pinMode(led0, OUTPUT);

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT); }

void loop() {

digitalWrite(led0, HIGH);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, HIGH);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, LOW);

delay(100);

digitalWrite(led0, HIGH);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

delay(100);

digitalWrite(led0, HIGH);

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

delay(100);

digitalWrite(led0, HIGH);

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

delay(100);

digitalWrite(led0, LOW);

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, LOW);

delay(250);

digitalWrite(led0, HIGH);

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

delay(250);

digitalWrite(led0, HIGH);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, HIGH);

delay(80);

digitalWrite(led0, HIGH);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, HIGH);

digitalWrite(led4, LOW);

delay(80);

digitalWrite(led0, HIGH);

digitalWrite(led1, LOW);

digitalWrite(led2, HIGH);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(80);

digitalWrite(led0, HIGH);

digitalWrite(led1, HIGH);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

delay(80);

digitalWrite(led0, HIGH);

digitalWrite(led1, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

delay(2500);   }

 

^^;;

I had a mistake at second work. The ‘pinMode’. pinMode must be wrote in each LED’s number. But I wrote it just once on the top. Then, the 4 LED’s brightness was too weak, except the top one. Now I know that pinMode is need in every single LED number.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s