1. Creating Something Unique

    On this part of the lab I used a force-sensor in combination with a speaker to produce some sound. First, I had to decide what were the ranges my sensor was giving me, so I used the serial monitor. The results of the serial monitor were 140 and 0, 140 being the number when it had the most pressure on it and 0 for the least. Having this numbers I divided 140 into 3, to create 3 different ranges;The first range being a number in between 19 and 47, the second one between 46 and 93 and the third 92 and over. Respectively a note was given to each one of these ranges, C4, D4 and E4. The result was, a system that operates as the force sensor is pressed with different forces, to produce different melodic sounds.

    This was the code done to obtain this result:

    #include <Tone.h>
    Tone mytone; // declare a tone name

    void setup() {
    // initialize the tone
    mytone.begin(8);
    mytone.play(NOTE_B3);
    delay (500);
    mytone.stop();
    delay (500);
    }

    void loop()
    {
    int inVar = analogRead(0);// read the analog input
    if((inVar>= 20) && (inVar<=46)) { //when the variable is in between 19 and 47
    mytone.play(NOTE_C4);// play note C4
    }

    else if((inVar>= 47) && (inVar<=92)) {// when the variable is in between 46 and 93
    mytone.play(NOTE_D4);//play note D4
    }

    else if(inVar>= 92) {//when the variable is 92 or over
    mytone.play (NOTE_E4);//play note E4

    }
    if(inVar<19){
    mytone.stop();
    }
    }