/*
* Project: Blink2-task 22
* Author: Jane-Maree Howard
* Date: Monday 08/03/2010
* Platform: Arduino 18
* Purpose: To demonstrate blink time for two external LEDs,
* & writing to the Serial Monitor (SM)
* Operation: Sets up 2 output pins in setup() method;
* Declares 2 pin definition variables, for red & yellow LEDs;
* Sets up output to serial port & thus to SM
* Each differently-coloured LED blinks alternately,
* & the word "Red " or "Yellow " is written to the SM @ each blink..
* .. & repeat
*/
int ylwLedPin = 12; // yellow LED connected to digital pin 12
int redLedPin = 11; // red LED connected to digital pin 11
int dLay = 200; // delay variable
// The setup() method runs once, when the sketch starts
void setup()
{
//Now open the serial port..
Serial.begin(9600); // ..& set data transmission rate to SM at 9600Baud
// initialize digital pins 11 & 12 as outputs
pinMode(redLedPin, OUTPUT);
pinMode(ylwLedPin, OUTPUT);
}//end setup()
// Loop turns red LED (pin 11) on, prints the word "Red " to the SM,
// waits 200 milliseconds, turns red LED off,
// turns yellow LED on, prints the word "Yellow " to the SM,
// waits 200 milliseconds, turns yellow LED off, &..
// ..repeats endlessly while Arduino has power
void loop()
{
digitalWrite(redLedPin, HIGH); // turn red LED on
Serial.print("Red "); // print the word "Red " to SM
delay(200); // delay 200 milliseconds
digitalWrite(redLedPin, LOW); // then turn red LED off;
digitalWrite(ylwLedPin, HIGH); // turn yellow LED on,
Serial.print("Yellow "); // print the word "Yellow " to SM,
delay(200); // delay 200 milliseconds,
digitalWrite(ylwLedPin, LOW); // turn yellow LED off
}//end loop()
No comments:
Post a Comment