User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 3: Sensing - Potentiometers

Submitted by Seth Horrigan on Fri, 09/19/2008 - 10:40

Assignment: Sensing: Potentiometers

Collaborators:

 

Description

I used two potentiometers to control three LEDs. One controlled the blink rate, the other controlled the intensity. All three LEDs varied together; however, they are set to blink on and off in a cycle thus giving the appearance of the lights chasing each other (an "interesting mapping between the rotational position pot and LED output"). This effect is accenuated by grouping the LEDs in a circle, giving the appearance of the light flowing around the circle.

 

Components Used

  • 3 220 Ohm resistors
  • 3 LEDs - red, green and blue
  • 1 Arduino board
  • 1 generic solderless breadboard
  • 2 rubber bands to secure the Arduino board to the breadboard
  • 2 potentiometers
  • solder (to attach wires to the potentiometers
  • wires

Image

 

 

Arduino Code

/*
* one pot dims, the other pot changes the blinking rate
* modification of the following
*
http://www.arduino.cc/en/Tutorial/AnalogInput
*/
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 = 10; // select the pin for the LED 2
int led3Pin = 11; // select the pin for the LED 3
void setup() {
pinMode(led1Pin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(led2Pin, OUTPUT); // declare the led2Pin as an OUTPUT
pinMode(led3Pin, OUTPUT); // declare the led3Pin as an OUTPUT
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking

delay(pot2Val/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led1Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led2Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led3Pin, pot1Val/4); // dim LED to value from pot1
delay(pot2Val/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led1Pin, 0); // dim LED to completely dark (zero)
delay(pot2Val/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led2Pin, 0); // dim LED to completely dark (zero)
delay(pot2Val/3); // stop the program for some time, meaning, LED is on for this time
analogWrite(led3Pin, 0); // dim LED to completely dark (zero)
}