Theory and Practice of Tangible User Interfaces

Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!

A Siren Light in two colors

Project Members:
kartikeya

Description:

Use 2 Potentiometers to control the blinking and brightness of two LED's

I used the sample code for controlling blinking and brightness from the Lab Homepage, adjusted the basic potentiometer circuit worked out in the class to include the additional potentiometer, and then modified the code as shown below to allow the two LED's to blink out of phase. When viewed through a diffuser this gives the appearance of a light "blinking" from blue to green. The speed of the blinking is controlled by the potentiometer controlling the blinking (pin 0 on the microcontroller), while the brightness of the blinking is controlled by the brightness controlling potentiometer (pin 1 on the microcontroller) (see picture of the circuit)

Components:

LED's - 1 Blue, 1 Green

2 Potentiometers

Code:

/*
* one pot dims, the other pot changes the blinking rate
* modification of the following
*/

/************************************************************
/************************************************************
/* This modification in the code causes the two LED's to blink with alternating brightness (when blue is bright, green is dim and vice versa). Causing it to look like a siren when viewed using a diffuser.*/

int pot1Pin = 0; // select the input pin for the potentiometer 1
int pot2Pin = 1; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int led1Pin = 9; // select the pin for the LED 1
int led2Pin = 11; // select the pin for the LED 2
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
}
void loop() {

int c1 = 1;
int c2 = 100;
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming

analogWrite(led1Pin, pot1Val/2);
analogWrite(led2Pin, pot1Val*2);
// dim LED to value from pot1
delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(led1Pin, pot1Val*2);
analogWrite(led2Pin, pot1Val/2); // dim LED to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time

}

Images: