User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Assignment 3: Pots and LEDs

Submitted by michael_lee on Fri, 09/19/2008 - 00:32

Assignment: Sensing: Potentiometers

Collaborators:

Assignment: Sensing: Potentiometers
Collaborators:

Assignment: Sensing: Potentiometers
Collaborators:

Description

For this lab, I followed the directions given in class. In addition, I added an additional LED and pot I had at home. I reused my diffuser with cotton (instead of a packing peanut) from the last assignment.

More information about the code and additional parts for the assignment are described below.

Components Used

  • x4 220 Ohm resistors
  • x4 LEDs - red, green, yellow, and blue
  • x4 Potentiometers
  • Wires
  • 1 Arduino NG board
  • Cosmetic Cotton Squares
  • Dosage cup from Vick's Dayquil Medicine

Code + Extras

For the assignment, I wired up four different colored LEDs (RGBY). Using the arduino programming language, I wrote code that associated a potentiometer for each LED.

For the "interesting" portion of the assignment, I set a threshold value midway through the pot. From 0 to 127, the LED starts from OFF (analog value 0) and increments up to fully on (analog value 255). Once the pot reaches the midway point, it begine to flash rapidly. Adjusting the pot higher will continue to slow down the rate of blinking.

Here is a text diagram of what is going on:

 

Analog Value: 0 -------------------------------------- 127 -------------------------------------- 255

LED:              | Off -------> + intensity -------> Full || (fast blink) ---> - blink rate ---> (slow blink)|

 

 

Images

 

 

 

 

Source Code

// Analog pin settings
int aIn = 0, bIn = 1, cIn = 2, dIn = 3;

// Digital pin settings
int aOut = 6, bOut = 9, cOut = 10, dOut = 11;

// Pot Values
int aVal = 0, bVal = 0, cVal = 0, dVal = 0;

// Variables for comparing values between loops
int i = 0;            // Loop counter
int wait = (1000);    // Delay between most recent pot adjustment and output
int blinkDelay = 0;   // Blink delay

int checkSum     = 0;
int prevCheckSum = 0;
int sens         = 3; 

void setup()
{
  pinMode(aOut, OUTPUT);
  pinMode(bOut, OUTPUT);   
  pinMode(cOut, OUTPUT);
  pinMode(dOut, OUTPUT); 
  Serial.begin(9600);     // Open serial communication for reporting
}

void loop()
{
  i += 1; // Count loop

  aVal = analogRead(aIn) / 4;  // read input pins, convert to 0-255 scale
  bVal = analogRead(bIn) / 4; 
  cVal = analogRead(cIn) / 4;
  dVal = analogRead(dIn) / 4;
  
  doCheck(aOut, aVal);
  doCheck(bOut, bVal);
  doCheck(cOut, cVal);
  doCheck(dOut, dVal);

  if (i % wait == 0)
    prevCheckSum = checkSum;  // Update the values
}

// Determine whether to blink or change intensity
void doCheck(int pin, int value)
{
  if (value == 0)
    digitalWrite(pin, LOW); 
  else if (value <= 127)
    doIntensity(pin, value*2); 
  else
    doBlinking(pin, value);
}

// Adjust Intensity
void doIntensity(int pin, int value)
{
  analogWrite(pin, value);
}

// Adjust Blink Rate
void doBlinking(int pin, int blinkDelay)
{
  digitalWrite(pin, HIGH);
  delay(blinkDelay); 
  digitalWrite(pin, LOW);
  delay(blinkDelay);      
}