06 March 2010

Task 12 - turn 1 off-board LED on while the other is turned off, delay, then reverse LED states



/*

* Project: blink-task12
* Author: Jane-Maree Howard
* Date: Tuesday 05/03/2010
* Platform: Arduino 18
* Purpose: To demonstrate variable blink times for the built-in LED & external LEDs
* Operation: Sets up output pins (3 off) in setup() method;
* Declares pin definition variables (3 off)
* Defines loop() to perform various LED blinking & delay operations
*/

int ledPin = 13; // on-board LED connected to digital pin 13
int ylwLedPin = 12; // yellow LED connected to digital pin 12
int redLedPin = 11; // red LED connected to digital pin 11
int dLay = 1000; // delay variable

// The setup() method runs once, when the sketch starts
void setup()
{
// initialize the 3 digital pins as outputs:
pinMode(ledPin, OUTPUT);
pinMode(ylwLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
// turn them all on, wait, then turn both off-board LEDs off, wait, then begin loop()
digitalWrite(ylwLedPin, HIGH); // turn yellow LED on
digitalWrite(redLedPin, HIGH); // turn red LED on
digitalWrite(ledPin, HIGH); // turn on-board LED on
delay(dLay*8); // delay 8 seconds

digitalWrite(ylwLedPin, LOW); // turn yellow LED off
digitalWrite(redLedPin, LOW); // turn red LED off
}//end setup()

void loop()
{
delay(4*dLay); // first, wait for 4 seconds
digitalWrite(ylwLedPin, LOW); // turn yellow LED off
digitalWrite(redLedPin, HIGH); // turn red LED on
delay(4*dLay); // delay 4 seconds
digitalWrite(ylwLedPin, HIGH); // turn yellow LED on
digitalWrite(redLedPin, LOW); // turn red LED off
}//end loop()


//note that on-board LED stays on continously

No comments:

Post a Comment