Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laser Harp Arduino Code
int photoDiode1 = HIGH;
int photoDiode2 = HIGH;
int photoDiode3 = HIGH;
int photoDiode4 = HIGH;
int photoDiode5 = HIGH;
int photoDiode6 = HIGH;
int photoDiode7 = HIGH;
void setup() {
Serial.begin(9600);
}
void loop() {
photoDiode1 = digitalRead(3);
photoDiode2 = digitalRead(4);
photoDiode3 = digitalRead(5);
photoDiode4 = digitalRead(6);
photoDiode5 = digitalRead(7);
photoDiode6 = digitalRead(8);
photoDiode7 = digitalRead(9);
printPhotoDiodeValues();
writeMIDINotes();
//
// //play notes from F#-0 (0x1E) to F#-5 (0x5A):
// for (int note = 0x1E; note < 0x5A; note ++) {
// //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
// noteOn(0x90, note, 0x45);
// delay(100);
// //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
// noteOn(0x90, note, 0x00);
// delay(100);
// }
}
void printPhotoDiodeValues() {
// print photodiode values for debugging
Serial.print("value 1: ");
Serial.print(photoDiode1);
Serial.print(", ");
Serial.print("value 2: ");
Serial.print(photoDiode2);
Serial.print(", ");
Serial.print("value 3: ");
Serial.print(photoDiode3);
Serial.print(", ");
Serial.print("value 4: ");
Serial.print(photoDiode4);
Serial.print(", ");
Serial.print("value 5: ");
Serial.print(photoDiode5);
Serial.print(", ");
Serial.print("value 6: ");
Serial.print(photoDiode6);
Serial.print(", ");
Serial.print("value 7: ");
Serial.print(photoDiode7);
Serial.println("");
}
void writeMIDINotes() {
if (photoDiode1 == HIGH) {
}
if (photoDiode2 == HIGH) {
}
if (photoDiode3 == HIGH) {
}
if (photoDiode4 == HIGH) {
}
if (photoDiode5 == HIGH) {
}
if (photoDiode6 == HIGH) {
}
if (photoDiode7 == HIGH) {
}
}
// plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that
// data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.