Thursday, February 25, 2010

Task 18 - Like 17 but i can be any value. Try different ones. Later we can input this value from the keyboard.

//for-loop with counter variable i.
//It will get one led to blink 20 (different value) 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 =50;
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<20; 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