We kept working on our final project. We ordered aluminum frames to install the grid and also started to work on the fabrication for our project.

IMG_5605.MOV

Also added our p5 choir.

let port; // Serial port object
let midiAccess;
let output;

// New note sequences for each person
let personNotes = [
  [62, 63, 65], // Person 1
  [59, 60, 62, 63, 65, 67], // Person 2
  [55, 56, 58, 60, 62, 63], // Person 3
  [59, 60, 62, 63, 65, 67], // Person 4
  [59, 60, 62, 63, 65, 67], // Person 5
  [35, 36, 38, 39, 41, 43], //Person 6
  [31, 32, 34, 36, 38, 39], // Person 7
  [11, 12, 14, 15, 17, 19], // Person 8
  [7, 8, 10, 12, 14, 15], // Person 9
];

let noteDuration = 100; // Duration of MIDI notes
let maxIndex = 4; // Maximum index for note sequences (since each person has 5 notes)

function setup() {
  createCanvas(400, 400);
  background(220);

  // Initialize serial port
  port = createSerial();

  // Automatically connect to the first available port
  let usedPorts = usedSerialPorts();
  if (usedPorts.length > 0) {
    port.open(usedPorts[0], 57600); // Match the baud rate in Arduino
    console.log("Connected to port:", usedPorts[0]);
  } else {
    console.log("No serial ports available.");
  }

  // Request MIDI access
  navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure);

  textAlign(CENTER, CENTER);
  textSize(16);
  text("Waiting for serial data...", width / 2, height / 2);
}

function draw() {
  // Read incoming serial data
  let str = port.readUntil("\\n");
  if (str.length > 0) {
    // Split the incoming data into individual sensor readings
    let values = split(str.trim(), ",");

    if (values.length === 9) {
      // Read distances from all 9 sensors
      let distances = values.map((v) => int(v));

      background(220);

      // Display all sensor distances for debugging
      for (let i = 0; i < distances.length; i++) {
        text(
          `Sensor ${i}: ${distances[i]} cm`,
          width / 2,
          height - (100 + i * 30)
        );
      }

      // Map each sensor's distance to a note index for the corresponding person
      let noteIndexes = distances.map((distance) =>
        floor(map(distance, 0, 60, 0, maxIndex))
      );

      // Play the corresponding notes for all nine people
      playNotes(noteIndexes);
    }
  }
}

function playNotes(indexes) {
  for (let i = 0; i < indexes.length; i++) {
    // Ensure the note values are valid (non-undefined)
    let note = personNotes[i][indexes[i]];

    // Check for invalid notes
    if (note !== undefined) {
      // Send MIDI note for the corresponding person
      sendMIDIMessage(0x90 | i, note, 127); // Note On for person i

      // Schedule Note Off after noteDuration
      setTimeout(() => {
        sendMIDIMessage(0x80 | i, note, 0); // Note Off for person i
      }, noteDuration);
    } else {
      console.error("Invalid note values at index:", indexes[i]);
    }
  }
}

// Send a MIDI message
function sendMIDIMessage(status, data1, data2) {
  if (output) {
    // Ensure that data1 and data2 are valid integers
    if (typeof data1 === "number" && typeof data2 === "number") {
      output.send([status, data1, data2]);
      console.log(
        `MIDI Message: Status=${status}, Data1=${data1}, Data2=${data2}`
      );
    } else {
      console.error("Invalid MIDI data:", data1, data2);
    }
  } else {
    console.log("No MIDI output device available.");
  }
}

// Handle successful MIDI access
function onMIDISuccess(midi) {
  midiAccess = midi;
  output = Array.from(midiAccess.outputs.values())[0];
  if (output) {
    console.log("MIDI output device selected:", output.name);
  } else {
    console.log("No MIDI output device found.");
  }
}

function onMIDIFailure() {
  console.log("Failed to access MIDI.");
}

IMG_5607.MOV