Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.sound.*;
- import processing.serial.*;
- import processing.video.*;
- SoundFile cNote, dNote, eNote, fNote, gNote, aNote, bNote, highCNote;
- SoundFile highDNote, highENote, highFNote, highGNote, highANote, highBNote, highestCNote;
- Movie myMovie;
- PImage img;
- String myString = null;
- Serial myPort;
- int portNum = 6;
- int NUM_OF_VALUES = 5;
- int[] sensorValues;
- int[] sensorValuesPrev;
- void setup() {
- background(0);
- pixelDensity(displayDensity());
- size(3200, 680);
- myMovie = new Movie(this, "vidvid.mp4");
- myMovie.loop();
- myMovie.volume(0);
- textSize(30);
- text("Ironman Inspired Musical Gauntlet!", 10, 40);
- text("Try adjusting the potentiometer", 1100, 500);
- text("on the back to change intervals!", 1100, 540);
- textSize(15);
- text("[4] is value for potentiometer (1023/4)", 30, 530);
- textSize(30);
- img = loadImage("arrow2.png");
- setupSerial();
- cNote = new SoundFile(this, "PianoMiddleC.wav");
- dNote = new SoundFile(this, "PianoD.wav");
- eNote = new SoundFile(this, "PianoE.wav");
- fNote = new SoundFile(this, "PianoF.wav");
- gNote = new SoundFile(this, "PianoG.wav");
- aNote = new SoundFile(this, "PianoA.wav");
- bNote = new SoundFile(this, "PianoB.wav");
- highCNote = new SoundFile(this, "PianoHighC.wav");
- highDNote = new SoundFile(this, "PianoHighD.wav");
- highENote = new SoundFile(this, "PianoHighE.wav");
- highFNote = new SoundFile(this, "PianoHighF.wav");
- highGNote = new SoundFile(this, "PianoHighG.wav");
- highANote = new SoundFile(this, "PianoHighA.wav");
- highBNote = new SoundFile(this, "PianoHighB.wav");
- highestCNote = new SoundFile(this, "PianoHighC2.wav");
- }
- void draw() {
- img.resize(100, 100);
- image(img, 30, 550);
- image(myMovie, 525, 0);
- updateSerial();
- printArray(sensorValues);
- if (sensorValues[4] <= 255 && sensorValues[4] >= 0) {
- firstInterval();
- }
- if (sensorValues[4] <= 510 && sensorValues[4] >= 256) {
- secondInterval();
- }
- if (sensorValues[4] <= 763 && sensorValues[4] >= 511) {
- thirdInterval();
- }
- if (sensorValues[4] <= 1023 && sensorValues[4] >= 764) {
- fourthInterval();
- }
- arrayCopy(sensorValues, sensorValuesPrev);
- }
- void firstInterval() {
- if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
- cNote.play();
- }
- if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
- dNote.play();
- }
- if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
- eNote.play();
- }
- if (sensorValues[3] == 1 && sensorValuesPrev[3] == 0) {
- fNote.play();
- }
- }
- void secondInterval() {
- if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
- gNote.play();
- }
- if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
- aNote.play();
- }
- if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
- bNote.play();
- }
- if (sensorValues[3] == 1 && sensorValuesPrev[3] == 0) {
- highCNote.play();
- }
- }
- void thirdInterval() {
- if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
- highDNote.play();
- }
- if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
- highENote.play();
- }
- if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
- highFNote.play();
- }
- if (sensorValues[3] == 1 && sensorValuesPrev[3] == 0) {
- highGNote.play();
- }
- }
- void fourthInterval() {
- if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
- highANote.play();
- }
- if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
- highBNote.play();
- }
- if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
- highestCNote.play();
- }
- }
- void movieEvent(Movie m) {
- m.read();
- }
- void setupSerial() {
- printArray(Serial.list());
- myPort = new Serial(this, Serial.list()[ portNum ], 9600);
- myPort.clear();
- myString = myPort.readStringUntil( 10 );
- myString = null;
- sensorValues = new int[NUM_OF_VALUES];
- sensorValuesPrev = new int[NUM_OF_VALUES];
- }
- void updateSerial() {
- while (myPort.available() > 0) {
- myString = myPort.readStringUntil( 10 ); // 10 = '\n' Linefeed in ASCII
- if (myString != null) {
- String[] serialInArray = split(trim(myString), ",");
- if (serialInArray.length == NUM_OF_VALUES) {
- for (int i=0; i<serialInArray.length; i++) {
- sensorValues[i] = int(serialInArray[i]);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment