Final presentation- MELODY
#include <CapacitiveSensor.h>
CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5);
CapacitiveSensor cs_2_6 = CapacitiveSensor(2,6);
CapacitiveSensor cs_2_7 = CapacitiveSensor(2,7);
CapacitiveSensor cs_2_8 = CapacitiveSensor(2,8);
CapacitiveSensor cs_2_9 = CapacitiveSensor(2,9);
CapacitiveSensor cs_2_10 = CapacitiveSensor(2,10);
int push=0;
long total1old=100;
void setup()
{
cs_2_4.set_CS_AutocaL_Millis(0xFFFFFFFF);
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_2_4.capacitiveSensor(30);
long total2 = cs_2_5.capacitiveSensor(30);
long total3 = cs_2_6.capacitiveSensor(30);
long total4 = cs_2_7.capacitiveSensor(30);
long total5 = cs_2_8.capacitiveSensor(30);
long total6 = cs_2_9.capacitiveSensor(30);
long total7 = cs_2_10.capacitiveSensor(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug window spacing
if(total1>1) Serial.print("D");
if(total2>1) Serial.print("F");
if(total3>10) Serial.print("G");
if(total4>1700) Serial.print("H");
if(total5>1000) Serial.print("J");
if(total6>1000) Serial.print("K");
if(total7>1000) Serial.print("L");
delay(1000);
}
import processing.sound.*;
import processing.serial.*;
Serial myPort;
int val;
SoundFile file,file1,file2,file3,file4,file5,file6,file7;
PImage imgbg,imgdo1,imgre,imgmi,imgfa,imgso,imgla,imgti,imgdor,imgsp;
void setup(){
myPort=new Serial(this,"COM3",9600);
imgbg=loadImage("bookbg4.png");
imgdo1=loadImage("do1.png");
imgre=loadImage("re.png");
imgmi=loadImage("mi.png");
imgfa=loadImage("fa.png");
imgso=loadImage("so.png");
imgla=loadImage("la.png");
imgti=loadImage("ti.png");
imgdor=loadImage("dor.png");
imgsp=loadImage("sample.png");
size(770,500);
//imageMode(CENTER);
}
void keyPressed()
{
file = new SoundFile(this, "do.wav");
file1 = new SoundFile(this, "re.wav");
file2 = new SoundFile(this, "mi.wav");
file3 = new SoundFile(this, "fa.wav");
file4 = new SoundFile(this, "sol.wav");
file5 = new SoundFile(this, "la.wav");
file6 = new SoundFile(this, "si.wav");
file7 = new SoundFile(this, "dor.wav");
if(key=='d') file.play();
if(key=='f') file1.play();
if(key=='g') file2.play();
if(key=='h') file3.play();
if(key=='j') file4.play();
if(key=='k') file5.play();
if(key=='l') file6.play();
if(key==';') file7.play();
}
void draw()
{
background(255);
image(imgsp,100,400);
image(imgbg,1,20);
image(imgdo1,140,65);
image(imgre,180,55);
image(imgmi,220,45);
image(imgfa,260,40);
image(imgso,300,30);
image(imgla,340,25);
image(imgti,380,16);
image(imgdor,420,8);
if ( myPort.available() > 0)
{
// If data is available,
val = myPort.readChar(); // read it and store it in val
} else
{
val = 'Z';
}
if(val=='D'){file.play();}
if(val=='F'){file1.play();}
if(val=='G'){file2.play();}
if(val=='H'){file3.play();}
if(val=='J'){file4.play();}
if(val=='K'){file5.play();}
if(val=='L'){file6.play();}
}


沒有留言:
張貼留言