Making Things Interactive

March 6, 2008

Midterm – Light Piano

Filed under: 7: Mid-Term Project,Lingshui Wang — lingshui @ 2:09 pm

So, I built a prototype for this out of some chipboard, wires, LEDs, and 3 potentiometers. I was working with dimming and lighting the LEDs in arrays depending on the state of the potentiometer. Right now, as I am new to working with brightness etc (and my analog pins don’t seem to want to transmit voltage to the LEDs for some strange reason…), the potentiometers are basically still acting as simple switches, with the dimming and lighting on LEDs on a timed script depending on the buttonstate of the potentiometer. Here’s the source code, I’m currently working on a new one to see if I can get the lights to match up with the potentiometer values.

int left1 = 3; //setting LED and potentiometer pins
int left2 = 5;
int leftSense = 0;
int right1 = 6;
int right2 = 9;
int rightSense = 1;
int bot1 = 10;
int bot2 = 11;
int botSense = 2;
int brightness = 0; //setting brightness values
int brightness1 = 0;
int brightness2 = 0;
int brightness3 = 0;
int brightness4 = 0;
int brightness5 = 0;
int val; //setting potentiometer values
int val2;
int val3;

void setup()
{
Serial.begin (9600); //serial library for troubleshooting
pinMode(left1, OUTPUT); //setting inputs and outputs
pinMode(left2, OUTPUT);
pinMode(leftSense, INPUT);
pinMode(right1, OUTPUT);
pinMode(right2, OUTPUT);
pinMode(rightSense, INPUT);
pinMode(bot1, OUTPUT);
pinMode(bot2, OUTPUT);
pinMode(botSense, INPUT);
}

void loop()
{
val = analogRead(leftSense); //define “val”
val2 = analogRead(rightSense);
val3 = analogRead(botSense);
Serial.println (val); //print values for troubleshooting
Serial.println (val2);
Serial.println (val3);
if (val >= 500) //switch value over one half…
{
if (brightness < 255) //if brightness of array 1 is not maxed... { brightness ++; //increase brightness for array 1 brightness1 --; //decrease brightness for array 2 analogWrite(left1, brightness); analogWrite(left2, brightness1); delay(5); } else if (brightness == 255) //however, if brightness of array 1 is maxed... { analogWrite(left1, 255); //stay constant at array 1 on, array 2 off analogWrite(left2, 0); brightness1 = 0; //reset brightness values so if switch is turned back, smooth transition } } else if (val < 500) //however, if switch value below one half... { if (brightness1 < 255) //brightness of array 2 not maxed... { brightness --; //array 1 dim brightness1 ++; //array 2 light analogWrite(left1, brightness); analogWrite(left2, brightness1); delay(5);} else if (brightness1 == 255) //however, if brightness of array 2 is maxed... { analogWrite(left1, 0); //stay constant at array 1 off, array 2 on analogWrite(left2, 255); brightness = 0; //set value back to 0 to provide smooth transition } } if (val2 >= 500) //rinse and repeat for other sides…
{
if (brightness2 < 255) { brightness2 ++; brightness3 --; analogWrite(right1, brightness2); analogWrite(right2, brightness3); delay(5); } else if (brightness2 == 255) { analogWrite(right1, 255); analogWrite(right2, 0); brightness3 = 0; } } else if (val2 < 500) { if (brightness3 < 255) { brightness2 --; brightness3 ++; analogWrite(right1, brightness2); analogWrite(right2, brightness3); delay(5);} else if (brightness3 == 255) { analogWrite(right1, 0); analogWrite(right2, 255); brightness2 = 0; } } if (val3 >= 500)
{
if (brightness4 < 255) { brightness4 ++; brightness5 --; analogWrite(bot1, brightness4); analogWrite(bot2, brightness5); delay(5); } else if (brightness4 == 255) { analogWrite(bot1, 255); analogWrite(bot2, 0); brightness5 = 0; } } else if (val3 < 500) { if (brightness5 < 255) { brightness4 --; brightness5 ++; analogWrite(bot1, brightness4); analogWrite(bot2, brightness5); delay(5);} else if (brightness5 == 255) { analogWrite(bot1, 0); analogWrite(bot2, 255); brightness4 = 0; } } }[/sourcecode] Schematic:

parts list:

27 LEDs

3 potetiometers / distance sensors

wire + solder

casing

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: