Saturday, April 10, 2010

For Loop: Task 17 and 18

This is the code i wrote for Task 17. It makes one LED blink 5 times and then another to blink once.

int del = 500;
int LEDPin2 = 2;
int LEDPin3 = 3;
void setup()
{
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
}

void loop()
{
for (int count = 1; count < 6; count++)
{
digitalWrite(LEDPin2, HIGH);
delay(del);
digitalWrite(LEDPin2, LOW);
delay(del);
}
digitalWrite(LEDPin3, HIGH);
delay(del);
digitalWrite(LEDPin3, LOW);
delay(del);
}


This is the code I wrote for task 18. This is like the code from 17 but there is a variable that is used to change the amount of times the first LED blinks.

int del = 500;
int LEDPin2 = 2;
int LEDPin3 = 3;
int countnum = 5; //This variable changes the amout of times the LEDPin2 LED blinks.
void setup()
{
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
}

void loop()
{
for (int count = 1; count < (countnum + 1); count++)
//For Loop uses the variable countnum to determine the duration of the loop.
{
digitalWrite(LEDPin2, HIGH);
delay(del);
digitalWrite(LEDPin2, LOW);
delay(del);
}
digitalWrite(LEDPin3, HIGH);
delay(del);
digitalWrite(LEDPin3, LOW);
delay(del);
}

No comments:

Post a Comment