Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Lab 3 - Fun with Potentiometers

Project Members: 
Isaac Salier-He...

Description

Utilizing analog input from three potentiometers, we can create a spectrum of variations in the output of our LED's. With the program below, here's what the three potentiometers can do:

1. Control blink rate. Turning the pot all the way to the right stops the blinking and keeps the LED light steady.

2. Control brightness across all three LED's simultaneously. This way, we can fade in and out while maintaining the same diffused color.

3. Control the combined color output. Each color fades in and out appropriately to allow a full turn of the pot to output the red-orange-yellow-green-cyan-blue-magenta continuum.

Components

  • breadboard
  • 3 220 Ohm resistors
  • wires (black/orange for ground, yellow for pot output and analog connections, red for 5V, green for output connections)
  • 3 LED's (red, green, blue)
  • 3 potentiometers (including 5V red wire, output yellow wire, black ground wire)
  • Plastic/paper diffuser
  • Arduino board
  • USB cable
  • trusty rubber bands

Code

Below is the modified code:

/*
* "Coffee-cup" Color Mixer:
* Code for mixing and reporting PWM-mediated color
* Assumes Arduino 0004 or higher, as it uses Serial.begin()-style communication
*
* Modified by Isaac Salier-Hellendag
* dish@ischool.berkeley.edu
* Tangible UI i290-13
* Lab 3 - 3 potentiometers and LEDs
*
* Using this program, the potentiometers now control the following:
* 1. Color (continuum from red->orange->yellow->green->cyan->blue->magenta
* 2. Blink Rate
* 3. Brightness (of all three LEDs together)
*
*/

// Analog pin settings
int blinkIn = 0; // Potentiometers connected to analog pins 0, 1, and 2
int colorIn = 1; // (Connect power to 5V and ground to analog ground)
int brightnessIn = 2;

// Digital pin settings
int blueOut = 11; // LEDs connected to digital pins 9, 10 and 11
int greenOut = 10; // (Connect cathodes to digital ground)
int redOut = 9;

// Values
int blinkVal = 0; // Variables to store the input from the potentiometers
int colorVal = 0;
int brightnessVal = 0;

// Colors for Spectrum
int blueRgb = 0;
int greenRgb = 0;
int redRgb = 0;

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

int checkSum = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens = 3; // Sensitivity theshold, to prevent small changes in
// pot values from triggering false reporting

void setup()
{
pinMode(blueOut, OUTPUT); // sets the digital pins as output
pinMode(greenOut, OUTPUT);
pinMode(redOut, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}

void loop()
{
// Get blink value.
blinkVal = analogRead(blinkIn);

// Do a blink.
blinkOn();
if(blinkVal > 10) {
delay(blinkVal);
blinkOff();
delay(blinkVal);
}
}

void blinkOn() {
colorVal = analogRead(colorIn);
brightnessVal = analogRead(brightnessIn) / 100;

// Get blue for colorVal spectrum
if(colorVal < 408) {
blueRgb = 0;
} else if(colorVal >= 408 && colorVal < 612) {
blueRgb = ((5 * colorVal) / 4) - 510;
} else if(colorVal >= 612) {
blueRgb = 255;
}

// Get green for colorVal spectrum
if(colorVal == 0) {
greenRgb = 0;
} else if(colorVal >= 204 && colorVal <= 612) {
greenRgb = 255;
} else if(colorVal >= 816) {
greenRgb = 0;
} else if(colorVal < 204) {
greenRgb = ((5 * colorVal) / 4);
} else {
greenRgb = ((-5 * colorVal) / 4) + 1020;
}

// Get red for colorVal spectrum
if(colorVal <= 204) {
redRgb = 255;
} else if(colorVal >= 408 && colorVal <= 816) {
redRgb = 0;
} else if(colorVal > 204 && colorVal < 408) {
redRgb = ((-5 * colorVal) / 4) + 510;
} else {
redRgb = ((5 * colorVal) / 4) - 1021;
}

if(redRgb > 255) redRgb = 255;

// Multiply RGB values by brightness.
blueRgb = (brightnessVal * blueRgb) / 10;
greenRgb = (brightnessVal * greenRgb) / 10;
redRgb = (brightnessVal * redRgb) / 10;

analogWrite(blueOut, blueRgb);
analogWrite(greenOut, greenRgb);
analogWrite(redOut, redRgb);

}

void blinkOff() {
analogWrite(blueOut, 0);
analogWrite(greenOut, 0);
analogWrite(redOut, 0);
}

Photos available at:

http://www.flickr.com/photos/46877131@N00/sets/72157602082606346

See it in action:

http://www.youtube.com/v/Vize0NrIHTY 


Comments

nice work! you got it ALL to

nice work! you got it ALL to work! thanks for the video!


Powered by Drupal - Design by Artinet