User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Three Potentiometers: Color Fading

Submitted by ngandomi on Wed, 09/24/2008 - 13:42

Assignment: Sensing: Potentiometers

Collaborators:

 

Description:

Combine the use of three potentiometers and analog input to with the arduino board to create a color fading and mixing device.

 

Materials:

  • Three LEDs (red, green, blue)
  • Three Potentiometers
  • Arduino Board
  • breadboard
  • USB cable
  • Three 220ohm resistors
  • Diffuser (Packing foam)
  •  

    Sample Code:

     

     

    /*

    * AnalogInput

    * by DojoDave <http://www.0j0.org>

    *

    * Turns on and off a light emitting diode(LED) connected to digital

    * pin 13. The amount of time the LED will be on and off depends on

    * the value obtained by analogRead(). In the easiest case we connect

    * a potentiometer to analog pin 2.

    *

    * http://www.arduino.cc/en/Tutorial/AnalogInput

    */

    //Input 3 pots, connected to 3 colors, dim the colors according to change in pot input

     

    int potPin = 1;

    int potPin2 = 2; // select the input pin for the potentiometer 1 and 2 and 3

    int potPin3 = 3;

    int ledPin = 11; // red select the pin for the LED

    int ledPin2 = 10; //green

    int ledPin3 = 9; //blue

     

    int val = 0; //variables to store the incoming values from pots 1-3

    int val2 = 0;

    int val3 = 0;

     

    void setup() {

    pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT

    pinMode(ledPin2, OUTPUT);

    pinMode(ledPin3, OUTPUT);

    Serial.begin(9600);

    }

     

    void loop() {

    // potPin controls red

    val = analogRead(potPin); //read from sensor

    Serial.println("red " + val); //display value

    analogWrite(ledPin, val/4); //change brightness

     

    //potPin2 controls green

    val2 = analogRead(potPin2);

    Serial.println("green " + val2);

    analogWrite(ledPin2, val2/4);

     

    //potPin3 controls blue

    val3 = analogRead(potPin3);

    Serial.println("blue " + val3);

    analogWrite(ledPin3, val3/4);

     

     

    }