title: Playing a wav sample on Arduino when a button is pressed
body: <p>I've been struggling to make an Arduino to play samples (loaded on an SD card and connected to the Arduino Uno board) whenever a button is pressed but with no success. When I run the code it does not wait for the button to be pressed, it starts playing the sample right away. </p>
  
  <p>It doesn't even recognise that a button has been pressed. This works perfectly however when I just make it play different frequencies through a buzzer. But as soon as I switch to wav samples instead of basic frequencies, it does not want to work. </p>
  
  <pre><code>#include &lt;SD.h&gt; //Include the library.
  #include &lt;TMRpcm.h&gt; //Include the library.
  
  TMRpcm tmrpcm; //Creating a player object.
  const int chipSelect = 4;
  
  
  void setup()
  {
  
    pinMode(9,INPUT);
  
    Serial.begin(9600); //Initializing serial port. Speed 9600.
    if(!SD.begin(chipSelect)) //If the card is available.
    {
      Serial.println("SD fail"); //Write in the serial port "SD fail".
      return; //Return.
    }
    Serial.println("SD working");
  
    if(digitalRead(9)==1){  
    tmrpcm.play("transMono1.wav"); //Play music file 
     Serial.println("button 1 pressed");
    }
  }
  
  void loop()
  {
  </code></pre>