Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We need to initalize a few of the pins from our Arduino.
- int lightPin1 = 0; // Analog 0 from the output of multiplexer #1.
- int lightPin2 = 1; // Analog 1 from the output of multiplexer #2.
- int control0 = 6; // Selector channel 0 (S0)
- int control1 = 7; // Selector channel 1 (S1)
- int control2 = 8; // Selector channel 2 (S2)
- int chord[] = {0X30, 0X32, 0X34, 0X35, 0X37, 0X39, 0X3B, 0X3C, 0X3E, 0X40, 0X41, 0X43, 0X45, 0X47, 0X48, 0X4A};
- // WAVESHIELD STUFF
- void setup()
- {
- Serial.begin(31250); // Begin serial communication. This describes with what frequency the Arduino
- // communicates with the computer (where the serial monitor is viewed).
- //Serial.begin(9600);
- //Serial.println(F("Hello world"));
- pinMode(control0, OUTPUT); // This makes the control pins outputs.
- pinMode(control1, OUTPUT);
- pinMode(control2, OUTPUT);
- pinMode(lightPin1, INPUT);
- pinMode(lightPin2, INPUT);
- }
- //16,7,
- // HELPER FUNCTION
- // plays a MIDI note.
- void noteOn(int cmd, int pitch, int velocity) {
- Serial.write(cmd);
- Serial.write(pitch);
- Serial.write(velocity);
- }
- void checkSwitch (int notea, int staira, int noteb, int stairb) {
- //delay(1000);
- int sensorValuea = analogRead(lightPin1);
- int sensorValueb = analogRead(lightPin2); // read the current output from the first phototransistor.
- //Serial.println(sensorValuea);
- //Serial.println(sensorValueb);
- //if (staira == 3) {return;}
- // Change the number 10 if lasers seem to dim. Height
- if (staira != 3) {
- if (sensorValuea < 10) { noteOn(0x90, notea, 0x45);}
- else { noteOn(0x90, notea, 0x00); }
- }
- if (sensorValueb < 10) { noteOn(0x90, noteb, 0x45);}
- else { noteOn(0x90, noteb, 0x00); };
- }
- // Finally the important loop where we register whether or not any of the phototransistors are being covered up or not.
- void loop() {
- for (int i = 0; i < 16; i++) { noteOn(0X90, chord[i], 0X00); }
- // STAIR 1
- digitalWrite(control0, LOW);
- digitalWrite(control1, LOW);
- digitalWrite(control2, LOW);
- //Serial.println(F("STAIR 1 and 8"));
- checkSwitch(chord[14], 1, chord[7], 8);
- //
- // STAIR 2
- digitalWrite(control0, LOW);
- digitalWrite(control1, LOW);
- digitalWrite(control2, HIGH);
- //Serial.println(F("STAIR 2 and 9"));
- checkSwitch(chord[13], 2, chord[6], 9);
- // STAIR 3
- digitalWrite(control0, LOW);
- digitalWrite(control1, HIGH);
- digitalWrite(control2, LOW);
- //Serial.println(F("STAIR 3 and 10"));
- //checkSwitch(chord[13], chord[5]);
- checkSwitch(chord[13], 3, chord[5], 10);
- // STAIR 4
- digitalWrite(control0, LOW);
- digitalWrite(control1, HIGH);
- digitalWrite(control2, HIGH);
- //Serial.println(F("STAIR 4 and 11"));
- checkSwitch(chord[12], 4, chord[4], 11);
- // STAIR 5
- digitalWrite(control0, HIGH);
- digitalWrite(control1, LOW);
- digitalWrite(control2, LOW);
- //Serial.println(F("STAIR 5 and 12"));
- checkSwitch(chord[11], 5, chord[3], 12);
- // STAIR 6
- digitalWrite(control0, HIGH);
- digitalWrite(control1, LOW);
- digitalWrite(control2, HIGH);
- //Serial.println(F("STAIR 6 and 13"));
- checkSwitch(chord[10], 6, chord[2], 13);
- // STAIR 7
- digitalWrite(control0, HIGH);
- digitalWrite(control1, HIGH);
- digitalWrite(control2, LOW);
- //Serial.println(F("STAIR 7 and 14"));
- checkSwitch(chord[9],7, chord[1], 14);
- // STAIR 8
- digitalWrite(control0, HIGH);
- digitalWrite(control1, HIGH);
- digitalWrite(control2, HIGH);
- //Serial.println(F("STAIR 8 and 15"));
- checkSwitch(chord[8], 8, chord[0], 15);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement