User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

LED's controlled by Potentiometers

Submitted by naryasece on Wed, 09/24/2008 - 22:06

Assignment: Sensing: Potentiometers

Collaborators:

Description

We use potentiometers to control various aspects of the blinking LEDs

Components Used

 

  • 3 Light Emitting Diodes
  • Wires
  • 2 Potentiometers
  • Arduino board
  • Breadboard

 

Arduino Code

 

This code lets the user control the brightness of the two LED's with a potentiometer
/*
 * one pot fades one led
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 */
int potPin = 2;   // select the input pin for the potentiometer
int ledPin = 9;   // select the pin for the LED
int val = 0;      // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
  Serial.println(val);
  analogWrite(ledPin, val/4); // analogWrite can be between 0-255
}

This code lets the user control the flashing rate with one Pot and the brightness with another.

/*
 * one pot fades one led
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 */
int potPin = 2;   // select the input pin for the potentiometer
int blinkpin=3;  //blinkpin is the potometer that controls the blinking delay
int ledPin = 9;   // select the pin for the LED
int val = 0;      // variable to store the value coming from the sensor
int blinkdelay=0; //variable to store the value coming from the blink control Pot
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
  blinkdelay= analogRead(blinkpin); //read the value from the blink control Pot, between 0 - 1024
  Serial.println(val);
  Serial.println(blinkdelay);
  analogWrite(ledPin, val/4); // analogWrite can be between 0-255
  analogWrite(11,0);
  delay(blinkdelay);
  analogWrite(ledPin, 0);
  analogWrite(11, val/4);// analogWrite to the other led
  delay(blinkdelay);

}

Picture of my arduino board