Lazer Harp

Adam Grabowski and Dan Joyce

Our electronics project is a harp which has lazers instead of strings. To play it you simply break one of the eight lazer beams with a finger, hand, etc. and a tone is played through a piezo.

Code

To make this happen we used a code that looked something simlar to:

int speaker = 9; // declares the speaker as part of the code

int one = 1; // delares pin............ 1

int two = 2; // delares pin............. 2

int three = 3; // delares pin............ 3

int four = 4; // delares pin............. 4

int five = 5; // delares pin............ 5

int six = 6; // delares pin............ 6

int seven = 7; // delares pin............ 7

int eight = 8; // delares pin............ 8

int ten = 10; // delares pin............. 10

int c = digitalRead( one); // declares a digitalRead on pin 1

int d = digitalRead (two); // declares a digitalRead on pin 2

int e = digitalRead ( three); // declares a digitalRead on pin 3

int f = digitalRead (four) ; // declares a digitalRead on pin 4

int g = digitalRead (five); // " " 5

int a = digitalRead (six); // " " 6

int b = digitalRead (seven); // " " 7

int C = digitalRead (eight); // " " 8

void setup () {

pinMode (speaker, OUTPUT); // declares pin 9 as an output

pinMode (one, INPUT); // declares pin 1 as input

pinMode (two, INPUT); // declares pin 2 as input

pinMode (three, INPUT); // declares pin 3 as input

pinMode (four, INPUT); // declares pin 4 as input

pinMode (five, INPUT); // declares pin 5 as input

pinMode (six, INPUT); // declares pin 6 as input

pinMode (seven, INPUT); // declares pin 7 as input

pinMode (eight, INPUT); // declares pin 8 as input

}

void loop ()

{

int cthree = 3822; // declares value for a variable

int dthree = 3405; // ditto

int ethree = 3033; // same

int fthree = 2863; // mismo

int gthree = 2551; // still the same

int athree = 2272; // this ones different...oh wait! it's the same.

int bthree = 2024; // nope

int cfour = 1911; // honestly? you're still reading this? wow. get a life. i mean seriosly, why would anyone have the God given attention span as well as have nothing better to do than sit here and read this ridiclously long and arduous comment?

int c = digitalRead(one); // same digital read stuff as before

int d = digitalRead(two); // more digital read stuff

int e = digitalRead(three); // digitalread

int f = digitalRead(four) ; // digitalread

int g = digitalRead (five); //

int a = digitalRead (six); //

int b = digitalRead (seven); //

int C = digitalRead (eight);

if (c == LOW) // indicates that if the digitalRead on pin 1 is "LOW" then....

{

digitalWrite (speaker, HIGH); // .....turn speaker on...

delayMicroseconds (cthree); // wait for this amount of time in microseconds(the variable was declared earlier)

digitalWrite (speaker, LOW); // turn speaker off

delayMicroseconds (cthree); // wait this amount of time in microseconds

} // rinse, and repeat!

if (d == LOW) // if the digitalRead on pin 2 "LOW" then...

{

digitalWrite (speaker , HIGH); // ....do this similar stuff with different delay

delayMicroseconds (dthree);

digitalWrite (speaker, LOW); // all of these if statements are doing the same thing: turning speakers on and off but with differing amounts of delay in between. this causes tones of differing pitches to be played based on the amounts of delay.

delayMicroseconds (dthree);

}

if (e == LOW)

{

digitalWrite (speaker, HIGH);

delayMicroseconds (ethree);

digitalWrite (speaker, LOW);

delayMicroseconds (ethree);

}

if (f == LOW)

{

digitalWrite (speaker, HIGH);

delayMicroseconds ( fthree);

digitalWrite (speaker, LOW);

delayMicroseconds (fthree);

}

if (g == LOW)

{

digitalWrite (speaker, HIGH);

delayMicroseconds (gthree);

digitalWrite (speaker, LOW);

delayMicroseconds (gthree);

}

if (a == LOW)

{

digitalWrite (speaker, HIGH);

delayMicroseconds(athree);

digitalWrite (speaker, LOW);

delayMicroseconds(athree);

}

if (b == LOW)

{

digitalWrite (speaker, HIGH);

delayMicroseconds ( bthree);

digitalWrite (speaker, LOW);

delayMicroseconds (bthree);

}

if (C == LOW)

{

digitalWrite (speaker, HIGH);

delayMicroseconds (cfour);

digitalWrite (speaker, LOW);

delayMicroseconds (cfour);

}

}

What!?!

Essentially all this code is doing is checking to see whether our eight pins (which are hooked up to photoresistors) are high or low. if they are low then the arduino tells the pin that the speaker is hooked up to to turn on and off with differing amounts of delay in between each. As a result, different tones are produced based on the amount of delay in between the turning on and off.