Week 11 Reading reflection

While going through the text, a specific passage that took my attention is the discussion about hearing aids. Unlike glasses, whose design has undergone comparatively less change, the writer highlights the evolving nature of hearing aids, emphasizing not only the modifications in their appearance but also the constant transformation of their discreet placement.

And in the part where, ‘Simple meets universal’, the author explores the complexities of designing for special needs, especially when dealing with a minority of the population. On one hand, there is a compelling business argument against further fragmenting the market by tailoring designs for small percentages of users. The concern here is that such a specialized approach might limit the product’s reach and economic viability.

Conversely, the concept of inclusive design, also known as universal design, introduces a principle-based contention. Inclusive design, by definition, aims to cater to the entire population. This definition intertwines two critical aspects: the acknowledgment that individuals possess varying abilities, and a recognition that people may have diverse needs and preferences regardless of their abilities. The former is commonly addressed through multimodal interfaces, incorporating visual, audible, and tactile cues to accommodate those with impaired touch, hearing, and/or sight. Meanwhile, the latter is often managed through multifunctional platforms, incorporating numerous features to appeal to a broad range of users.

A central question raised by the author is whether the pursuit of universal design, aiming to accommodate a diverse user base, might inadvertently lead to overly complex designs. There is a tension between the goal of inclusivity and the risk of creating designs that are intricate and potentially challenging to use. This prompts a consideration of how truly inclusive such designs are, and whether there are insights to be gained from navigating these design complexities.

Week 11: exercises

  1. Make something that uses only one sensor  on Arduino and makes the ellipse in p5 move on the horizontal axis, in the middle of the screen, and nothing on arduino is controlled by p5

    let rVal = 0;
    let alpha = 255;
    let left = 0;
    let right = 0;
    
    
    function setup() {
      createCanvas(640, 360);
      noFill();
      //create an ellipse with x position changing and y (300) position constant 
    }
    
    function draw() {
      background(255);
      
      
    
      if (!serialActive) {
        fill(0)
        text("Press Space Bar to select Serial Port", 20, 30);
      } else {
        fill(0)
        text("Connected", 20, 30);
      }
      let xPos = 300;
      xPos = map(alpha, 0, 1023, 0,640);
      ellipse(xPos, 150, 50, 50);
    
      console.log(alpha);
    }
    
    function keyPressed() {
      if (key == " ") {
        // important to have in order to start the serial connection!!
        setUpSerial();
      }
    }

    For this question, we decided to create a simple ellipse that changes direction based on the values from the potentiometer.

  2. make something that controls the LED brightness from p5t
    function keyPressed() {
      if (key == " ") {
        // important to have in order to start the serial connection!!
        setUpSerial();
      }
      if (key== "1"){
        left = 50;
      }
      
      if (key== "2"){
        left = 100;
      }
      if (key== "3"){
        left = 255;
      }
      if (key =="4"){
        right = 50;
      }
      if (key =="5"){
        right = 100;
      }
      if (key =="6"){
        right =255;
      }
    }

    This one was pretty simple. Pressing the keys 1-6 increases/decreases the brightness of the left or right LED light. 1-3 correspond to the left, while 4-6 correspond to the right led.

  3. take the gravity wind example (https://editor.p5js.org/aaronsherwood/sketches/I7iQrNCul) and make it so every time the ball bounces one led lights up and then turns off, and you can control the wind from one analog sensor.
let rVal = 0;
let alpha = 255;
let left = 0;
let right = 0;
let velocity;
let gravity;
let position;
let acceleration;
let wind;
let drag = 0.99;
let mass = 20;

function setup() {
  createCanvas(640, 360);
  noFill();
  position = createVector(width/2, 0);
  velocity = createVector(0,0);
  acceleration = createVector(0,0);
  gravity = createVector(0, 0.1*mass);
  wind = createVector(0,0);
}

function draw() {
  background(255);
  applyForce(wind);
  applyForce(gravity);
  velocity.add(acceleration);
  velocity.mult(drag);
  position.add(velocity);
  acceleration.mult(0);
  ellipse(position.x,position.y,mass,mass);
  if (position.y > height-mass/2) {
      velocity.y *= -0.9;  // A little dampening when hitting the bottom
      position.y = height-mass/2;
    
    }
  console.log(position.y);
  if(position.y >= 330){
    left = 1;
  }
  else if(position.y <= 330){
    left = 0;
  }
  console.log(rVal);
  wind.x = map(alpha, 0, 1023, -1, 1);
  

 

  if (!serialActive) {
    fill(0)
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    fill(0)
    text("Connected", 20, 30);
  }
}
function applyForce(force){
  // Newton's 2nd law: F = M * A
  // or A = F / M
  let f = p5.Vector.div(force, mass);
  acceleration.add(f);
}

function keyPressed() {
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
  if(key == "1"){
    left = 1;
  }
  
}

For changing the wind direction, we followed similar logic to the first question. The ball changes direction based on values mapped from the potentiometer.

 

Week 11 – Assignment

Video

P5.js code

let velocity;
let gravity;
let position;
let acceleration;
let wind;
let drag = 0.99;
let mass = 50;

let didTouch = 0;

function setup() {
  createCanvas(640, 360);
  noFill();
  position = createVector(width/2, 0);
  velocity = createVector(0,0);
  acceleration = createVector(0,0);
  gravity = createVector(0, 0.5*mass);
  wind = createVector(0,0);
}

function draw() {
  background(255);
  applyForce(wind);
  applyForce(gravity);
  velocity.add(acceleration);
  velocity.mult(drag);
  position.add(velocity);
  acceleration.mult(0);
  ellipse(position.x,position.y,mass,mass);
  if (position.y > height-mass/2) {
      didTouch = 1;
      velocity.y *= -0.9;  // A little dampening when hitting the bottom
      position.y = height-mass/2;
  } else {
    didTouch = 0
  }
}

function applyForce(force){
  // Newton's 2nd law: F = M * A
  // or A = F / M
  let f = p5.Vector.div(force, mass);
  acceleration.add(f);
}

function keyPressed(){
  if (keyCode==LEFT_ARROW){
    wind.x=-1;
  }
  if (keyCode==RIGHT_ARROW){
    wind.x=1;
  }
  if (key==' '){
    mass=random(15,80);
    position.y=-mass;
    position.x = width / 2
    velocity.mult(0);
  }
  
  if (key == 's') {
    setUpSerial();
  }
}

// This function will be called by the web-serial library
// with each new *line* of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function
function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // make sure there is actually a message
    // split the message
    let fromArduino = split(trim(data), ",");
    // if the right length, then proceed
    if (fromArduino.length == 1) {
      // only store values here
      // do everything with those values in the main draw loop
      
      // We take the string we get from Arduino and explicitly
      // convert it to a number by using int()
      // e.g. "103" becomes 103
      windValue = int(fromArduino[0]);
      wind = createVector(map(windValue, 0, 1023, -2, 2), 0)
    }

    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = didTouch + "\n";
    print(sendToArduino)
    writeSerial(sendToArduino);
  }
}

Arduino code

// Week 11.2 Example of bidirectional serial communication

// Inputs:
// - A0 - sensor connected as voltage divider (e.g. potentiometer or light sensor)
// - A1 - sensor connected as voltage divider 
//
// Outputs:
// - 2 - LED
// - 5 - LED

int ledPin = 5;
int potPin = A2;

void setup() {
  // Start serial communication so we can send data
  // over the USB connection to our p5js sketch
  Serial.begin(9600);

  // We'll use the builtin LED as a status output.
  // We can't use the serial monitor since the serial connection is
  // used to communicate to p5js and only one application on the computer
  // can use a serial port at once.
  pinMode(LED_BUILTIN, OUTPUT);

  // Outputs on these pins
  pinMode(ledPin, OUTPUT);

  // Blink them so we can check the wiring
  digitalWrite(ledPin, HIGH);
  delay(200);
  digitalWrite(ledPin, LOW);



  // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data

    int ledLight = Serial.parseInt();
    if (Serial.read() == '\n') {
      digitalWrite(ledPin, ledLight);
      int sensor = analogRead(potPin);
      delay(5);
      Serial.println(sensor);
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
}

 

Week 11 – Reading Reflection

Design Meets Disability

This reading, about how designing for disabilities can change the way we think of design, was extremely well structured and raised many thoughts. Firstly, it was interesting to observe how the evolution of glasses from being perceived as a medical device to a fashion accessory mirrored my personal journey with glasses. I have needed to wear glasses since third grade, and in the first few years I greatly resented them and preferred how I looked without them. My eyes progressively got worse every year, and so I always had to update my glasses. In high school, something shifted and I did not mind much how I looked with glasses anymore, and I began to look forward to the opportunity to get new glasses. As the reading stated, it is having the choice between different options that empowers the consumer to “accessorize” their image. The fact that the accessory is needed to enable human function does not take away from its worth as a fashion statement. Last year I got a new pair of golden framed glasses, and that was the first time I felt happy to be wearing them, as one of my favorite book characters also wears golden framed glasses.

The reading brought up the question of if it is possible to “appropriate” things like eyewear, or in the future, hearing aids and prostheses. Personally, I find it just a tad bit annoying when people wear non-prescription glasses just for the looks, because they have the privilege of not actually needing them to see. In the future, if development in the design of hearing aids follows the trajectory of that of glasses, will people start sporting “hearwear” even if they do not have hearing loss? And how would this be received by Deaf communities? While there is no “community” of people with glasses, there are deaf communities with their own cultures, and so the two situations are not really comparable. And then, what about prostheses?

I also felt that the principle presented in the reading of achieving positive image without invisibility was especially powerful, as it reminded me of discourses within queer history about how the goal should not be to assimilate (into heteronormative culture) in order to gain acceptance, but to have the freedom of visibility without receiving harm for it.

Week 10 Assignment– IM (Ivan & Muhammad) Techno

Concept

It took a while for us to come up with a properly functioning musical instrument with a decent sound. At first, we tried to incorporate an ultrasonic sensor for controlling the height of a sound, a servo motor to create a beat, and a flex sensor for controlling the duration of the notes. It turned out to be fine, but we weren’t satisfied with the quality of the sound or its instability. After a little experimenting, we finally decided to use transistors to amplify the sound, which gave the music a feel of the techno genre.

Technical structure

We used the ultrasonic sensor to control the height of a sound. The B10K potentiometer controls the duration of the note, while the B100K potentiometer controls the volume of the sound. The potentiometer, as mentioned earlier, amplifies the sound.

We decided to use a transistor to amplify the signal to the speaker. Moreover, we added an external 9V power supply to power the speaker, and these additions greatly enhanced the volume and clarity of the sound. The potentiometer controlling the volume is connected in series with the input signal to the speaker from the Arduino, and so the physical reduction of the voltage of the signal by adjusting the resistance of the potentiometer controls the volume. Therefore, we use the potentiometer as a variable resistor instead of an input here.

On the other hand, the potentiometer used for the delay is used to get analog input to the Arduino, which is then used to control the delay interval in code. This is just a way to showcase the different use cases of the same components.

Video demonstration:

Code

int mapDistanceToIndex(float distance) {
// Map distances into array index (2 cm steps from 5 cm to 15 cm)
// int index = constrain((distance - MIN_DIST) / 2, 0, ARRAY_LENGTH - 1);
int dist = int(distance);
int index = constrain(map(dist, MIN_DIST, MAX_DIST, 0, ARRAY_LENGTH - 1), 0, ARRAY_LENGTH - 1);
return index;
}

void loop() {
float dist = getDistance();


noteDuration = map(analogRead(OFFSET_DIMMER), 0, 1023, 100, 500);

if (millis() - noteStartTime >= noteDuration) {
// noTone(SPEAKER_PIN);
// delay(10);
// Play a funky note continuously based on the distance range
if (dist >= MIN_DIST && dist <= MAX_DIST) {
int note = FUNKY_NOTES[mapDistanceToIndex(dist)];


Serial.print(dist);
Serial.print("cm ");
Serial.print(note);
Serial.print("HZ");
Serial.print(" with duration = ");
Serial.print(noteDuration);
Serial.println();

// Check if the note duration has elapsed, then check for a new note

// If the note has changed, start a new note
if (note != lastNote) {
lastNote = note;
tone(SPEAKER_PIN, note);
noteStartTime = millis(); // Record the start time of the current note
}
} else {
noTone(SPEAKER_PIN);
}
}

Reflection

We have succeeded in creating a new instrument that wouldn’t just become the replication of already existing ones. Furthermore, we had a chance to experiment with new sensors and get experience working with transistors and potentiometers, implementing them in one project. We believe there’s more potential for this project, especially if we could use mp3 files. Nevertheless, we had fun working on this project, experimenting with Arduino.

Musical instrument

coNCEPT

Our initial idea was to create a piano using the ultrasonic sensor. However, after realising this idea was too mainstream and simple, we decided to create an instrument that can be fully played by 2 people since it involves using 3 hands.

Process

void loop() {
  // read the input on analog pin 0:
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);
  
  switchState = digitalRead(switchPin);

  if (switchState ==1){
    //sensor 1
    if(sensorValue1 > 500){
      currentState+=100;
    }
    else if (sensorValue1>250 && sensorValue1 < 500) {
      currentState+=10;
    }

    else if (sensorValue1 < 250){
      currentState+=1;
    }

    //sensor 2
    if(sensorValue2 > 500){
      currentState+=100;

    }
    else if (sensorValue2>250 && sensorValue2 < 500) {
      currentState+=10;

    }

    else if (sensorValue2 < 250){
      currentState+=1;
    }

    //sensor 3
    if(sensorValue3 > 500){
      currentState+=100;

    }
    else if (sensorValue3>250 && sensorValue3 < 500) {
      currentState+=10;
    }

    else if (sensorValue3 < 250){
      currentState+=1;
    }

  }
  else{
    //sensor 1
    if(sensorValue1 > 500){
      currentState+=100;
    }
    else if (sensorValue1>250 && sensorValue1 < 500) {
      currentState+=10;
    }

    else if (sensorValue1 < 250){
      currentState+=1;
    }

    //sensor 2
    if(sensorValue2 > 500){
      currentState+=100;

    }
    else if (sensorValue2>250 && sensorValue2 < 500) {
      currentState+=10;
    }

    else if (sensorValue2 < 250){
      currentState+=1;
    }

    //sensor 3
    if(sensorValue3 > 500){
      currentState+=100;
    }
    else if (sensorValue3>250 && sensorValue3 < 500) {
      currentState+=10;
    }

    else if (sensorValue3 < 250){
      currentState+=1;
    }
  }

if(switchState == 0){
  switch(currentState){
    case 3: //3 low
      tone(8, NOTE_B3, 250);
      delay(250*1.30);
      break;
    case 12: //2 low 1 mid
      tone(8, NOTE_C4, 250);
      delay(250*1.30);
      break;
    case 21: //2 mid 1 low
    tone(8, NOTE_D4, 250);
      delay(250*1.30);
      break;
    case 30:
    tone(8, NOTE_E4, 250);
      delay(250*1.30);
      break;
    case 102: //1 high 2 low
    tone(8, NOTE_F4, 250);
      delay(250*1.30);
      break;
    case 111: //1 high 1 mid 1 low
    tone(8, NOTE_G4, 250);
      delay(250*1.30);
      break;
    case 120: //1 high 2 mid
    tone(8, NOTE_A4, 250);
      delay(250*1.30);
      break;
    case 201: //2 high 1 low
    tone(8, NOTE_B4, 250);
      delay(250*1.30);
      break;
    case 210: //2 high 1 mid
    tone(8, NOTE_C5, 250);
      delay(250*1.30);
      break;
    case 300: //3 high
    tone(8, NOTE_D5, 250);
      delay(250*1.30);
      break;
  }
}

We placed 3 photoresistors inside 3 cups and depending on the amount of light detected, we mapped specific musical notes to each cup. To avoid treating analog sensors as if they were digital, we implemented distinct categorizations for each cup. Specifically, we established three cases based on the amount of light detected: low (<250), mid (250-500), and high (>500). To introduce an element of digital control, we incorporated a slide switch.

Video demonstration:

REFLECTIONS

Working on this project was a fun experience. Initially considering a piano, we opted for a more unconventional approach, transforming ordinary cups into interactive controllers. One aspect that has become evident during this project is the potential for aesthetic enhancement. Observing other students’ projects, I realized the impact a well-designed aesthetic can have on the overall appeal of the final product. While our focus was primarily on functionality, witnessing the visual creativity in other projects has inspired me to explore the aesthetic dimension further in future endeavors.

 

Week 10: Team Project

<How To Make an Instrument>

My Arduino project combines an ultrasonic distance measurement sensor, a switch button, and a buzzer to create an interactive instrument. The ultrasonic sensor, consisting of a trig pin (connected to pin 10) and an echo pin (connected to pin 11), is utilized to measure the distance between the sensor and an object. The setup initializes the pins and sets up serial communication. In the loop function, the sensor is triggered to emit ultrasonic waves, and the duration of the wave’s round trip is measured. The distance is then calculated in centimeters based on the speed of sound. Additionally, a switch button connected to analog pin A0 turns on the music when I press the switch button.

 

int trig = 10;
int echo = 11;
long duration;
long distance;
int switch;

void setup() {
  pinMode(echo, INPUT);

  pinMode(trig, OUTPUT);

  Serial.begin(9600);
}

void loop() {
  digitalWrite(trig, LOW); //triggers on/off and then reads data
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = (duration / 2) * .0344;    //344 m/s = speed of sound. We're converting into cm



  int notes[7] = {261, 294, 329, 349, 392, 440, 494}; //Putting several notes in an array
  //          mid C  D   E   F   G   A   B

  switch = analogRead(A0); //defining switch as digital button


  if (distance < 0 || distance > 50 || force < 100) { //if not presed and not in front

    noTone(12); //dont play music

  }

  else if ((force > 100)) {  //if pressed

    int sound = map(distance, 0, 50, 0, 6);  //map distance to the array of notes
    tone(12, notes[sound]);  //call a certain note depending on distance

  }


}

 

The musical aspect of the project involves an array of seven notes, representing the musical scale from mid-C to B. When the conditions are met (distance within a certain range and sufficient force applied), the distance is mapped to an index in the notes array. The corresponding note is then played using the tone function on pin 12. The project incorporates conditional statements to determine when to play a note and when to remain silent, providing an interactive experience where the user can generate musical tones by manipulating the distance and switch parameters.

 

I used this video to learn about the distance sensor and the tips to make a code for the music notes. To enhance my project, consider implementing error handling for the distance measurements, such as checking for valid sensor readings or outliers. I believe that adding comments to clarify the purpose of specific code sections can improve code readability, making it easier for others to understand the logic behind each step. Additionally, I want to incorporate debounce mechanisms for the switch button to prevent false triggers. Experimenting with different musical scales or incorporating dynamic melodies based on changing sensor inputs could add depth and creativity to the musical aspect of my project.

Week 10 – Musical instrument

Concept: We created a basic radio that switched between two channels, each playing different songs, by adjusting a potentiometer. Inspired by the upcoming festive season, even though it is too early, we decided to integrate the beloved tune “Jingle Bells” into our project.

Video Demonstration: musical instrument

Implementation:

We used a switch, a potentiometer, and a buzzer in our setup. The switch turns on and off the radio, and the potentiometer switches between channels. Initially, we planned to include two songs: “Jingle Bells” and “Let It Be.” However, converting “Jingle Bells” into playable chords was a bit of a challenge. Consequently, the potentiometer plays “Jingle Bells” when set in the first half and stays silent in the second half.

To achieve the authentic “Jingle Bells” melody, we discovered the chords and their timing online. These chords, when played together, compose a recognizable tune. We organized this chord information into an array named “melody” in our code. Each chord in this array was linked to a specific frequency, dictating the notes played. Assigning these frequencies to each chord enabled us to establish a precise sequence of notes within the melody array, ultimately generating the iconic “Jingle Bells” tune. Later in the loop, it iterates through the melody array. Within the loop, it retrieves each note’s frequency and plays it for a specified duration using the buzzer.

const int POTENTIOMETER_PIN = A0;
const int BUZZER_PIN = 3;
const int threshold = 512;

// Define each chord's frequency
#define C 261
#define D 294
#define E 329
#define F 349
#define G 392
#define A 440
#define B 493
#define REST 0

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int analogValue = analogRead(POTENTIOMETER_PIN);
  Serial.println(analogValue);

  if (analogValue > threshold) {
    playJingleBells();
  } else {
    noTone(BUZZER_PIN);
    delay(100); // Delay to reduce loop frequency
  }
}

void playJingleBells() {
  // Melody and Timing
  int melody[] = {
    E, E, E, REST,
    E, E, E, REST, E, G, C, D, E, REST,
    F, F, F, F, F, E, E, E, E, D, D, E, D, REST, G, REST,
    E, E, E, REST,
    E, E, E, REST, E, G, C, D, E, REST,
    F, F, F, F, F, E, E, E, G, G, F, D, C, REST
  };
  int noteDurations[] = {
    4, 4, 4, 4,
    4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
    4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
    4, 4, 4, 4,
    4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
    4, 4, 4, 4, 4, 4, 4
  };

  int melodySize = sizeof(melody) / sizeof(melody[0]);

  for (int i = 0; i < melodySize; ++i) {
    int noteDuration = 1000 / noteDurations[i];

    if (melody[i] != REST) {
      tone(BUZZER_PIN, melody[i], noteDuration);
      delay(noteDuration); // Let the note play for its duration
    } else {
      delay(noteDuration); // If it's a rest, delay without tone
    }
    
    noTone(BUZZER_PIN); // Stop the note
    delay(50); // Delay between notes for spacing
  }
}

Reflection & Future Improvements: As it was mentioned before, we wanted to create a radio with two channels, playing two different songs such as “Jingle Bells” and “Let It Be”, depending on the resistance of the potentiometer: the first half plays one song, and the second half another. However, we spent a lot of time working on our beloved Christmas song, finding the right chords, and frequencies, and figuring out the logic of making it play, so we didn’t have much time left to work on the second song. Because of this, we decided to make another channel of our radio empty for now, so we could add the song in the future. In addition to that, we would like to work on the aesthetics in the future by creating the painted cardboard in the form of the radio to create a more realistic experience.

Week 10 – Reading Reflection

When I started reading the text “Hands”, I felt like the author was telling the obvious things. However, recalling how my little sister was born during the pandemic time with an iPad and iPhone at home, his words have value. My sister knows everything about the screens and how to manipulate them, but she might not know the basic things such as how to tie the shoes, hold the pen properly, etc. Because of this, I understand that pictures under glass are affecting the skills and reducing the capabilities of the hands, thus, reducing the real-life experience. What I mean by experience is that we are replacing the papers with screens, or table games such as chess and ping-pong with screen ‘dynamics’, but they don’t create the same tactile feeling… it is just a screen. 

Furthermore, the picture in the glass puts a huge emphasis on the vision, assuming that it might compensate for the tactile feelings. However, I think that this might be not the best inclusive solution for people with visual impairments. Hands give enough intuitive information for us to understand the material we are touching, how thick it is, how to manipulate it, etc, which cannot be replaced by the glass screen unless we look at it. As the author said, this is a good temporary solution, but not in the long term. So, he gave good ideas about the issues we have and now it is time to start thinking about the solutions for this issue. 

Overall, I think that our desire to touch, feel, and move cannot be replaced with visual aesthetics. 

Week 10 – Musical Instrument

For this assignment, we wanted to make a hovering keyboard. We used the ultrasonic distance measuring sensor to set specific distance ranges to specific notes. As the user would move their hand through different ranges, different notes would play. We also added a button to turn off the instrument completely in addition to implementing a maximum range beyond which the instrument doesn’t produce any sound.

Video:

#include "pitches.h"
// defines pins numbers
const int trigPin = A0;
const int echoPin = A1;
const int speakerPin = 8;
const int pushButton = A2;
// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT);  // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);   // Sets the echoPin as an Input
  pinMode()
  Serial.begin(9600);  // Starts the serial communication
  
}
void loop() {
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);  // delay in between reads for stability
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
  // Playing outside distance range or the instrument is turned off
  if (distance >= 40 || buttonState == 1) {
    noTone(speakerPin);
  }
  // Play C4 in first 10cm
  else if (distance >= 0 && distance <= 10) {
    tone(speakerPin, NOTE_C4, 1000 / 4);
  }
  // Play G4 in next 10cm
  else if (distance >= 11 && distance <= 20) {
    tone(speakerPin, NOTE_G4, 1000 / 4);
  }
  // Play A4 in next 10cm
  else if (distance >= 21 && distance <= 30) {
    tone(speakerPin, NOTE_A4, 1000 / 4);
  }
  // Play F4 in next 10cm
  else if (distance >= 31 && distance <= 40) {
    tone(speakerPin, NOTE_F4, 1000 / 4);
  }
}

Future Applications:

I think for future applications, the number of keys could be expanded to have 12 keys, and buttons to move up or down an octave so it could be a complete hovering piano with all possible keys present on a keyboard.