Thursday, February 25, 2010

Task 20 - blinking from 100ms to 1 sec back to 100ms.

//for-loop with counter variable i.
//program to get one led to increase its rate of blinking from 100ms to 1sec back to 100ms.
//Repeating forever.
// by Adam Randall

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


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


void loop()
{
for (i=100; i<1000; i=i+100)// for loop counter increasing i by 50
{
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(i);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(i);//delay
}
x=1000; //resets x back to 1000
for (x=1000; x>100; x=x-100)
{
digitalWrite(redLedPin, HIGH);//sets the pin to on
delay(x);//delay
digitalWrite(redLedPin, LOW);//sets the pin to off
delay(x);//delay
}
i=100; //resets i back to 100
}

No comments:

Post a Comment