Sunday, March 7, 2010

011 Blink2 Sketch

This sketch shows the on-board LED and a breadboarded LED going on and off alternately. I copied it straight from Peter's blog:

/*
Blink2
Turns on a LED on for half a second, then off for half a second, repeatedly. It also does the same to an off-board LED connected to pin 12 so that when one LED is on the other is off.
The circuit:
* LED connected from digital pin 13 to ground via resistor.
* second LED connected from digital pin 12 to ground via resistor. I used 330 ohms.
* 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


based on an orginal by H. Barragan for the Wiring i/o board
*/


int ledPin = 13; // LED connected to digital pin 13
int redLedPin = 12; // LED connected to digital pin 13
int del =500;


// The setup() method runs once, when the sketch starts


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


// the loop() method runs over and over again,
// as long as the Arduino has power


void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
digitalWrite(redLedPin, LOW); // set the LED on
delay(del); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
digitalWrite(redLedPin, HIGH); // set the LED off
delay(del); // wait for a second
}


Here is a picture:

...

and a video clip:

...

of it working. Thanks to my mate Roy for helping me set up the circuit (my first ever breadboard!) and for taking and getting me the clips.

LED Project

For my LED project, I have proposed a traffic light system, with red, amber and green lights. I will control corrspondingly coloured LEDs in sequence. I will model an UK traffic light as the sequence is prettier than in NZ, and gives me the opportunity to show a more complex pattern.

If this is insufficient, and if time permits, I will add a pedestrian control to the traffic light, to break the sequence on request to allow pedestrians to cross in safety.

010 (again) Flicker Sketch

This sketch shows the LED going on for 12 millseconds then off for 13 millisecond intervals. In ambient light, I can just see the flickering - I find this more distinguishable than when the light is on for 13 millseconds then off for 12 milliseconds:

/*
Flicker

Turns on an LED on for 12 millisecond, then off for 13 millisecond, repeatedly.

The circuit:
* LED connected from digital pin 13 to ground.

* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.


Created 5th March 2010
By Mike Goodwin

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

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

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(12); // wait for 12 milliseconds
digitalWrite(ledPin, LOW); // set the LED off
delay(13); // wait for 13 milliseconds
}

010 Dither Sketch

This sketch shows the LED going on and off at 10 millisecond intervals. In most lights, I can't see the flickering:

/*
Dither

Turns on an LED on for one centisecond, then off for one centisecond, repeatedly.

The circuit:
* LED connected from digital pin 13 to ground.

* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.


Created 5th March 2010
By Mike Goodwin

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

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

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(10); // wait for a centisecond
digitalWrite(ledPin, LOW); // set the LED off
delay(10); // wait for a centisecond
}

Thursday, March 4, 2010

009: Occult Sketch

Occulting is the opposite of flashing, where the light is on for longer than it is off. I learned that in a course on boatcraft. I increased the shorter interval to 100ms to make it doubly different:

/*
Occult

Turns on an LED on for one second, then off for one decisecond, repeatedly.

The circuit:
* LED connected from digital pin 13 to ground.

* Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example.


Created 5th March 2010
By Mike Goodwin

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

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

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for a centisecond
}

008: Flash Sketch

This is based on the Blink sketch, with the timing changed. The Flash duration is very low (10ms) but visible:

/*
Flash

Turns on an LED on for one centisecond, then off for one second, repeatedly.

The circuit:
* LED connected from digital pin 13 to ground.

* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.


Created 5 March 2010
By Mike Goodwin

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

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

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(10); // wait for a centisecond
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}