Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1.  
  2. // We need to initalize a few of the pins from our Arduino.
  3. int lightPin1 = 0; // Analog 0 from the output of multiplexer #1.
  4. int lightPin2 = 1; // Analog 1 from the output of multiplexer #2.
  5. int control0 = 6; // Selector channel 0 (S0)
  6. int control1 = 7; // Selector channel 1 (S1)
  7. int control2 = 8; // Selector channel 2 (S2)
  8.  
  9. int chord[] = {0X30, 0X32, 0X34, 0X35, 0X37, 0X39, 0X3B, 0X3C, 0X3E, 0X40, 0X41, 0X43, 0X45, 0X47, 0X48, 0X4A};
  10.  
  11. // WAVESHIELD STUFF
  12. void setup()
  13. {
  14. Serial.begin(31250); // Begin serial communication. This describes with what frequency the Arduino
  15. // communicates with the computer (where the serial monitor is viewed).
  16. //Serial.begin(9600);
  17. //Serial.println(F("Hello world"));
  18. pinMode(control0, OUTPUT); // This makes the control pins outputs.
  19. pinMode(control1, OUTPUT);
  20. pinMode(control2, OUTPUT);
  21. pinMode(lightPin1, INPUT);
  22. pinMode(lightPin2, INPUT);
  23. }
  24. //16,7,
  25. // HELPER FUNCTION
  26. // plays a MIDI note.
  27. void noteOn(int cmd, int pitch, int velocity) {
  28. Serial.write(cmd);
  29. Serial.write(pitch);
  30. Serial.write(velocity);
  31. }
  32.  
  33. void checkSwitch (int notea, int staira, int noteb, int stairb) {
  34. //delay(1000);
  35. int sensorValuea = analogRead(lightPin1);
  36. int sensorValueb = analogRead(lightPin2); // read the current output from the first phototransistor.
  37. //Serial.println(sensorValuea);
  38. //Serial.println(sensorValueb);
  39. //if (staira == 3) {return;}
  40.  
  41. // Change the number 10 if lasers seem to dim. Height
  42. if (staira != 3) {
  43. if (sensorValuea < 10) { noteOn(0x90, notea, 0x45);}
  44. else { noteOn(0x90, notea, 0x00); }
  45. }
  46.  
  47. if (sensorValueb < 10) { noteOn(0x90, noteb, 0x45);}
  48. else { noteOn(0x90, noteb, 0x00); };
  49. }
  50. // Finally the important loop where we register whether or not any of the phototransistors are being covered up or not.
  51. void loop() {
  52.  
  53. for (int i = 0; i < 16; i++) { noteOn(0X90, chord[i], 0X00); }
  54.  
  55.  
  56. // STAIR 1
  57. digitalWrite(control0, LOW);
  58. digitalWrite(control1, LOW);
  59. digitalWrite(control2, LOW);
  60. //Serial.println(F("STAIR 1 and 8"));
  61. checkSwitch(chord[14], 1, chord[7], 8);
  62.  
  63. //
  64. // STAIR 2
  65. digitalWrite(control0, LOW);
  66. digitalWrite(control1, LOW);
  67. digitalWrite(control2, HIGH);
  68. //Serial.println(F("STAIR 2 and 9"));
  69. checkSwitch(chord[13], 2, chord[6], 9);
  70.  
  71. // STAIR 3
  72. digitalWrite(control0, LOW);
  73. digitalWrite(control1, HIGH);
  74. digitalWrite(control2, LOW);
  75. //Serial.println(F("STAIR 3 and 10"));
  76. //checkSwitch(chord[13], chord[5]);
  77. checkSwitch(chord[13], 3, chord[5], 10);
  78.  
  79. // STAIR 4
  80. digitalWrite(control0, LOW);
  81. digitalWrite(control1, HIGH);
  82. digitalWrite(control2, HIGH);
  83. //Serial.println(F("STAIR 4 and 11"));
  84. checkSwitch(chord[12], 4, chord[4], 11);
  85.  
  86. // STAIR 5
  87. digitalWrite(control0, HIGH);
  88. digitalWrite(control1, LOW);
  89. digitalWrite(control2, LOW);
  90. //Serial.println(F("STAIR 5 and 12"));
  91. checkSwitch(chord[11], 5, chord[3], 12);
  92.  
  93. // STAIR 6
  94. digitalWrite(control0, HIGH);
  95. digitalWrite(control1, LOW);
  96. digitalWrite(control2, HIGH);
  97. //Serial.println(F("STAIR 6 and 13"));
  98. checkSwitch(chord[10], 6, chord[2], 13);
  99.  
  100. // STAIR 7
  101. digitalWrite(control0, HIGH);
  102. digitalWrite(control1, HIGH);
  103. digitalWrite(control2, LOW);
  104. //Serial.println(F("STAIR 7 and 14"));
  105. checkSwitch(chord[9],7, chord[1], 14);
  106.  
  107. // STAIR 8
  108. digitalWrite(control0, HIGH);
  109. digitalWrite(control1, HIGH);
  110. digitalWrite(control2, HIGH);
  111. //Serial.println(F("STAIR 8 and 15"));
  112. checkSwitch(chord[8], 8, chord[0], 15);
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement