User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Sensing: Potentiometers

Submitted by neha on Tue, 09/23/2008 - 12:51

Assignment: Sensing: Potentiometers

Collaborators:

For the optional part of this assignment, I used the two pots I had - one controlled the light intensity of one pin, and the other controlled the blinking rate of the other pin. A picture is attached below.

/*

* one pot dims one pin, the other pot changes the blinking rate of the other pin
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/

int pot1Pin = 2;   // select the input pin for the potentiometer 1
int pot2Pin = 3;   // 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
Serial.begin(9600); //open serial communication port
}

//connect pot1 to led1 and pot2 to led2
void loop() {
pot1Val = analogRead(pot1Pin)/4;   // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin)/4;   // read the value from pot 2, between 0 - 1024, for blinking
lightPin(pot1Val);
blinkPin(pot2Val);
}

void lightPin(int value)
{
analogWrite(led1Pin, value);
}

void blinkPin(int blinkDelay)
{
digitalWrite(led2Pin, HIGH);
delay( blinkDelay);
digitalWrite(led2Pin, LOW);
delay( blinkDelay);
}