Nicholas and Shama – Flute Box

For this assignment we decided to use pressure sensors to create a synth sound when pressed. We placed our sensors on a box and programmed everything on P5js and connected it with Arduino using serial control.

After getting our sound to work, we quickly realized that our chosen notes (c4,E4,G4,C5) more closely resemble a digital flute. We then aligned our sensors to the side of the box to mimic the setup of a flute, but in the medium of a box. Of course, our flute box has no air involved but the pressure added to the sensor does change the intensity of the sound produced which is pretty similar to how a flute intrinsically works.

We controlled the flow of data with a variable controlled with a switch, and only sent data to p5js if the switch was toggled using the sample code from class.

 while (Serial.available() > 0 && toggled) {

      // read the incoming byte:

    int analogReading = analogRead(FORCE_SENSOR_PIN);

    int analogReading1 = analogRead(FORCE_SENSOR_PIN1);

    int analogReading2 = analogRead(FORCE_SENSOR_PIN2);

    int analogReading3 = analogRead(FORCE_SENSOR_PIN3);

    Serial.print(analogReading);

    Serial.print(",");

    Serial.print(analogReading1);

    Serial.print(",");

    Serial.print(analogReading2);

    Serial.print(",");

    Serial.print(analogReading3);

    Serial.print("\n");

    Serial.println();

  }

 

To output the sound input by the sensors, we created an array of MonoSynth instances, in which each instance controlled the note being played and the volume.

monoSynth = [

      new p5.MonoSynth(),

      new p5.MonoSynth(),

      new p5.MonoSynth(),

      new p5.MonoSynth(),

  ];

  notes = [‘C4', 'E4', 'G4', 'C5']

function playSynth(i, val) {

  userStartAudio();

  let intval = int(val)

  let note = notes[i];

  // note velocity (volume, from 0 to 1)

  let velocity = intval<100?0:map(intval, 0, 1023, 0, 1);

  // time from now (in seconds)

  let time = 0;

  

  // note duration (in seconds)

  let dur = 1/6;

  if(intval > 100)

    monoSynth[i].play(note, velocity, time, dur);

}

if (inString.length > 0) {

    let sensors = split(inString, ","); // split the string on the commas

    if (sensors.length == 4) {

      // if there are three elements

      for(let i=0; i < sensors.length; i++){

        playSynth(i, sensors[i]);

      }

    }

  }

 

Since the velocity parameter in monoSynth.play() is continuous, we were able to map the input value to a value between 0 and 1, so when the user presses a key heavier, the sound plays louder.

Leave a Reply