Melody Steps
Concept:
Replicating the piano playing mat that we all used to play as children was the idea behind this assignment. Even those who are not musically inclined are drawn to play with the piano mat again because of how logically it was created. Why not make something that makes us all feel nostalgic, rather than just one of us? You’ll be overwhelmed with happiness as you play about with our design and hopefully be able to relive all your childhood memories in a way. This initiative will facilitate audience engagement and provide a means of connection to one another.
Code:
The code is for an Arduino setup that uses an ultrasonic sensor to measure distance and a force-sensitive resistor to detect pressure. It plays different musical notes based on the distance measured by the sensor, but only if a certain pressure threshold is exceeded on the resistor. If the measured distance is out of a specified range or the pressure is too low, no sound is played. The system uses this setup to create an interactive musical device where sound changes with distance and pressure.
int trig = 10; int echo = 11; long duration; long distance; int force; 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 force = analogRead(A0); //defining force as FSR data 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 } }
Reflections & Challenges:
One of the challenges we had while working on this project was the weakness of the sensors; if we had an ultrasonic sensor that measured the distance longer and a larger force detecting resistor, we would not have had any trouble playing notes. Therefore, we were forced to limit the user to playing notes (C-D-E-F-G-A) as a result of this.
Result: