Thursday, February 25, 2010

Task 17 - for-loop with counter variable i. Get one led to blink 5 times, using the for-loop, then the other to blink once. Repeat forever.

//for-loop with counter variable i.
//It will get one led to blink 5 times, using the for-loop, then the other to blink once.
//Repeating forever.
// by Adam Randall


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 12
int del =100;
int i = 0;
// The setup() method runs once, when the sketch starts


void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}


void loop()
{
for (i=1; i<6; i++){ // for loop counter
digitalWrite(ledPin, LOW); //sets the pin to off
delay(del); //delay
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(del);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(del);//delay
}
digitalWrite(ledPin, HIGH);//sets the pin to on
delay(del);//delay

}

No comments:

Post a Comment