Thursday, September 17, 2009

Arduino Color Mixing Lamp





Here we have the first attempt at learning how to properly write sketches and organize circuits using arduino. Below is a short video helping to illustrate the mixing of colors and the effects produced by this colorful lamp.

The script is as follows:

int redPin = 12; // Red LED connected to digital pin 12
int greenPin = 11; // Green LED connected to digital pin 11
int bluePin = 10; // Blue LED connected to digital pin 10

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

void setup() {
// initialize the digital pin as an output:
pinMode(redPin, OUTPUT); //sets the digital pin as output
pinMode(greenPin, OUTPUT); //sets the digital pin as output
pinMode(bluePin, OUTPUT); //sets the digital pin as output
}

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

void loop()
{
digitalWrite(redPin, HIGH); // set the Red LED on
digitalWrite(greenPin, LOW); // set the Green LED on
digitalWrite(bluePin, LOW); // set the Blue LED on
delay(500); // waits for half a second
digitalWrite(redPin, HIGH); // set the Red LED on
digitalWrite(greenPin, HIGH); // set the Green LED on
digitalWrite(bluePin, LOW); // set the Blue LED on
delay(250); // waits for a qurater of a second
digitalWrite(redPin, LOW); // set the Red LED on
digitalWrite(greenPin, HIGH); // set the Green LED on
digitalWrite(bluePin, LOW); // set the Blue LED on
delay(500); // waits for half a second
digitalWrite(redPin, LOW); // set the Red LED on
digitalWrite(greenPin, HIGH); // set the Green LED on
digitalWrite(bluePin, HIGH); // set the Blue LED on
delay(250); // waits for a quarter of a second
digitalWrite(redPin, HIGH); // set the Red LED on
digitalWrite(greenPin, LOW); // set the Green LED on
digitalWrite(bluePin, HIGH); // set the Blue LED on
delay(500); // waits for half a second
digitalWrite(redPin, LOW); // set the Red LED on
digitalWrite(greenPin, HIGH); // set the Green LED on
digitalWrite(bluePin, HIGH); // set the Blue LED on
delay(250); // waits for a quarter of a second
digitalWrite(redPin, LOW); // set the Red LED on
digitalWrite(greenPin, HIGH); // set the Green LED on
digitalWrite(bluePin, LOW); // set the Blue LED on
delay(500); // waits for half a second
digitalWrite(redPin, HIGH); // set the Red LED on
digitalWrite(greenPin, HIGH); // set the Green LED on
digitalWrite(bluePin, LOW); // set the Blue LED on
delay(250); // waits for a quarter of a second
}

The script follows the color progression as describe in lesson 3, but then doubled and reversed for the second half.