Guest User

Untitled

a guest
Dec 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. import processing.sound.*;
  2. import processing.serial.*;
  3. import processing.video.*;
  4. SoundFile cNote, dNote, eNote, fNote, gNote, aNote, bNote, highCNote;
  5. SoundFile highDNote, highENote, highFNote, highGNote, highANote, highBNote, highestCNote;
  6. Movie myMovie;
  7. PImage img;
  8.  
  9. String myString = null;
  10. Serial myPort;
  11.  
  12. int portNum = 6;
  13. int NUM_OF_VALUES = 5;
  14. int[] sensorValues;
  15. int[] sensorValuesPrev;
  16.  
  17.  
  18. void setup() {
  19. background(0);
  20. pixelDensity(displayDensity());
  21. size(3200, 680);
  22. myMovie = new Movie(this, "vidvid.mp4");
  23. myMovie.loop();
  24. myMovie.volume(0);
  25. textSize(30);
  26. text("Ironman Inspired Musical Gauntlet!", 10, 40);
  27. text("Try adjusting the potentiometer", 1100, 500);
  28. text("on the back to change intervals!", 1100, 540);
  29. textSize(15);
  30. text("[4] is value for potentiometer (1023/4)", 30, 530);
  31. textSize(30);
  32. img = loadImage("arrow2.png");
  33.  
  34.  
  35.  
  36.  
  37. setupSerial();
  38.  
  39.  
  40.  
  41. cNote = new SoundFile(this, "PianoMiddleC.wav");
  42. dNote = new SoundFile(this, "PianoD.wav");
  43. eNote = new SoundFile(this, "PianoE.wav");
  44. fNote = new SoundFile(this, "PianoF.wav");
  45.  
  46. gNote = new SoundFile(this, "PianoG.wav");
  47. aNote = new SoundFile(this, "PianoA.wav");
  48. bNote = new SoundFile(this, "PianoB.wav");
  49. highCNote = new SoundFile(this, "PianoHighC.wav");
  50.  
  51. highDNote = new SoundFile(this, "PianoHighD.wav");
  52. highENote = new SoundFile(this, "PianoHighE.wav");
  53. highFNote = new SoundFile(this, "PianoHighF.wav");
  54. highGNote = new SoundFile(this, "PianoHighG.wav");
  55.  
  56. highANote = new SoundFile(this, "PianoHighA.wav");
  57. highBNote = new SoundFile(this, "PianoHighB.wav");
  58. highestCNote = new SoundFile(this, "PianoHighC2.wav");
  59. }
  60.  
  61.  
  62. void draw() {
  63. img.resize(100, 100);
  64. image(img, 30, 550);
  65. image(myMovie, 525, 0);
  66.  
  67. updateSerial();
  68. printArray(sensorValues);
  69.  
  70.  
  71. if (sensorValues[4] <= 255 && sensorValues[4] >= 0) {
  72. firstInterval();
  73. }
  74.  
  75. if (sensorValues[4] <= 510 && sensorValues[4] >= 256) {
  76. secondInterval();
  77. }
  78.  
  79. if (sensorValues[4] <= 763 && sensorValues[4] >= 511) {
  80. thirdInterval();
  81. }
  82.  
  83. if (sensorValues[4] <= 1023 && sensorValues[4] >= 764) {
  84. fourthInterval();
  85. }
  86.  
  87.  
  88.  
  89. arrayCopy(sensorValues, sensorValuesPrev);
  90. }
  91.  
  92.  
  93.  
  94. void firstInterval() {
  95. if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
  96. cNote.play();
  97. }
  98.  
  99. if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
  100. dNote.play();
  101. }
  102.  
  103. if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
  104. eNote.play();
  105. }
  106.  
  107. if (sensorValues[3] == 1 && sensorValuesPrev[3] == 0) {
  108. fNote.play();
  109. }
  110. }
  111.  
  112. void secondInterval() {
  113.  
  114. if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
  115. gNote.play();
  116. }
  117.  
  118. if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
  119. aNote.play();
  120. }
  121.  
  122. if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
  123. bNote.play();
  124. }
  125.  
  126. if (sensorValues[3] == 1 && sensorValuesPrev[3] == 0) {
  127. highCNote.play();
  128. }
  129. }
  130.  
  131. void thirdInterval() {
  132.  
  133. if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
  134. highDNote.play();
  135. }
  136.  
  137. if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
  138. highENote.play();
  139. }
  140.  
  141. if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
  142. highFNote.play();
  143. }
  144.  
  145. if (sensorValues[3] == 1 && sensorValuesPrev[3] == 0) {
  146. highGNote.play();
  147. }
  148. }
  149.  
  150.  
  151. void fourthInterval() {
  152. if (sensorValues[0] == 1 && sensorValuesPrev[0] == 0) {
  153. highANote.play();
  154. }
  155.  
  156. if (sensorValues[1] == 1 && sensorValuesPrev[1] == 0) {
  157. highBNote.play();
  158. }
  159.  
  160. if (sensorValues[2] == 1 && sensorValuesPrev[2] == 0) {
  161. highestCNote.play();
  162. }
  163. }
  164.  
  165. void movieEvent(Movie m) {
  166. m.read();
  167. }
  168.  
  169. void setupSerial() {
  170. printArray(Serial.list());
  171. myPort = new Serial(this, Serial.list()[ portNum ], 9600);
  172. myPort.clear();
  173. myString = myPort.readStringUntil( 10 );
  174. myString = null;
  175.  
  176. sensorValues = new int[NUM_OF_VALUES];
  177. sensorValuesPrev = new int[NUM_OF_VALUES];
  178. }
  179.  
  180.  
  181.  
  182. void updateSerial() {
  183. while (myPort.available() > 0) {
  184. myString = myPort.readStringUntil( 10 ); // 10 = '\n' Linefeed in ASCII
  185. if (myString != null) {
  186. String[] serialInArray = split(trim(myString), ",");
  187. if (serialInArray.length == NUM_OF_VALUES) {
  188. for (int i=0; i<serialInArray.length; i++) {
  189. sensorValues[i] = int(serialInArray[i]);
  190. }
  191. }
  192. }
  193. }
  194. }
Add Comment
Please, Sign In to add comment