Project Members: 
Emelie Cheng
Kimberly_Lau
Matt Chew Spence
Srinivasan Ramaswamy
Description
A musical instrument that plays musical tracks and flashes LEDs depending upon which switch is pressed. Uses processing to play music.
Materials
- Plastic waterbottle
- coffee stirrers
- 5 Leds
- 5 10k resistors
- 5+ switches
- Balsa Wood
- Paper towel inner roll
- Blue tape
- Arduino & breadboard
Arduino Code
// define input pins for each switch
int switchOne = 2; //Pins 0 and 1 are used for Transmit/Receive and don't work for input
int switchTwo = 4; //pin3 appears to be BAD
int switchThree = 5;
int switchFour= 7; //so does pin6
int switchFive = 8;
// define variables to store the value coming from the switches
int valOne = LOW;
int valTwo = LOW;
int valThree = LOW;
int valFour = LOW;
int valFive = LOW;
void setup() {
// set the input mode for each pin
pinMode(switchOne, INPUT);
pinMode(switchTwo, INPUT);
pinMode(switchThree, INPUT);
pinMode(switchFour, INPUT);
pinMode(switchFive, INPUT);
Serial.begin(9600);
}
void loop() {
valOne = digitalRead(switchOne); // read the value from the sensor (High or Low)
if(valOne==HIGH) {
Serial.print(1);
}
valTwo = digitalRead(switchTwo); // read the value from switch
if(valTwo==HIGH) {
Serial.print(2);
}
valThree = digitalRead(switchThree); // read the value from switch
if(valThree==HIGH) {
Serial.print(3);
}
valFour = digitalRead(switchFour); // read the value from switch
if(valFour==HIGH) {
Serial.print(4);
}
valFive = digitalRead(switchFive); // read the value from switch
if(valFive==HIGH) {
Serial.print(5);
}
delay(100);
}
Processing Code
//Different start time
//To view this content, you need to install Java from java.com
import processing.serial.*;
import jmetude.*;
String portname = "COM8"; //COM7
Serial port;
int lf = 10;
int s =0 ;
int v=0;
int bytesRecieved = 0;
Etude e;
float notes[][] = {{e.E4, e.SQ},
{e.FS4, e.SQ},
{e.B4, e.SQ},
{e.CS5, e.SQ},
{e.D5, e.SQ},
{e.FS4, e.SQ},
{e.E4, e.SQ},
{e.CS5, e.SQ},
{e.B4, e.SQ},
{e.FS4, e.SQ},
{e.D5, e.SQ},
{e.CS5, e.SQ}};
void setup() {
size(200,100);
//println(Serial.list());
port = new Serial(this, portname, 9600);
if (port.available()<=0){
print(".");
delay(200);
}
//bytesRecieved = port.available();
//port.bufferUntil(lf);
//Initialization of Etude classes
e = new Etude(this);
e.createScore("score");
e.createPart("part1");
e.createPhrase("phrase1", notes);
e.createPhrase("phrase2", notes);
e.createPhrase("phrase3", notes);
e.transpose("phrase2",-12);
e.transpose("phrase3",24);
e.setPhraseStartTime("phrase2",6);
e.setPhraseStartTime("phrase3",12);
e.repeatPhrase("phrase1",12);
e.repeatPhrase("phrase2",10);
e.repeatPhrase("phrase3",8);
e.addPartPhrase("part1", "phrase1");
e.addPartPhrase("part1", "phrase2");
e.addPartPhrase("part1", "phrase3");
e.addScorePart("score","part1");}
void draw() {
background(40,40,40);
if (port.available()>0){
serialEvent(port.read());
//print(v);
//playMusic(v);
delay(1000);
}
}
void playMusic(int inst) {
e.stopMIDI();
// int inst = (int)random(0,127);
e.setPartInstrument("part1",inst);
e.playMIDI("score");
}
void serialEvent(int s) {
s = port.read();
print(s);
if (s==48){
print(s);
}
else{
s = s%127;
playMusic(s);
delay(200);
}
}
Picture