05 March 2010

Task 9 - LED blinking but mostly ON


/*
*Blink2_ON_off

*Turns on a red LED on for most of a second, then off for 50 milliseconds, repeatedly.
*It also does the opposite to an off-board LED connected to pin 12 so that when one LED is on the other is off.

*The circuit:
* A red LED connected from digital pin 13 to ground via resistor.
* A yellow LED connected from digital pin 12 to ground via resistor. I used 220 ohms,
* (I think - they're so small I can barely read the colours: JMH).
* Note: On most Arduino boards, there is already an LED on the board
* connected to pin 13.
* Created 1 June 2005
* By David Cuartielles. Adapted by Peter Brook (& Jane-Maree Howard, 25feb2010)
* based on an orginal by H. Barragan for the Wiring i/o board
*/

int redLedPin = 13; // red LED connected to digital pin 13
int ylwLedPin = 12; // yellow LED connected to digital pin 13
int del =50; // short delay time

// The setup() method runs once, when the sketch starts
void setup()
{
// initialize two digital pins as outputs:
pinMode(redLedPin, OUTPUT);
pinMode(ylwLedPin, OUTPUT);
}//end setup()

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
digitalWrite(redLedPin, HIGH); // set the LED on
digitalWrite(ylwLedPin, LOW); // set the LED on
delay(del); // wait for a second
digitalWrite(redLedPin, LOW); // set the LED off
digitalWrite(ylwLedPin, HIGH); // set the LED off
delay(del*20); // wait for a second (50*20 milliseconds)
}//end loop()

1 comment:

  1. Well, it's tedious putting a BR tag at the start of every line..
    ..but at least it works!

    But it IS annoying..

    ReplyDelete