Help triggering sound

Why can you not just go read the instructions? It's all in the threads I mentioned. It's like this:

#include <SPI.h>
#include <SD.h>
#include "TMRpcm.h" // includes the library for music playback
#include <LiquidCrystal.h> // includes the library code for LCD

#define SENSORPIN1 6 // sets SENSORPIN1 as pin 6
#define SENSORPIN2 5 // sets SENSORPIN2 as pin 5
#define SENSORPIN3 8 // sets SENSORPIN3 as pin 8
#define SD_ChipSelectPin 10 // sets the SD card as pin 10

TMRpcm music; //Lib object is named "music"
LiquidCrystal lcd(0, 1, 2, 3, 4, 7); // initialize the library with the numbers of the interface pins

int sensorState1 = 0; // variable for reading IR sensor 1
int sensorState2 = 0; // variable for reading IR sensor 2
int HomeScore; // variable for Home Score
int AwayScore; // variable for Away Score

void setup() {

  pinMode(SENSORPIN1, INPUT); // initiate SENSORPIN1 as an input
  digitalWrite(SENSORPIN1, HIGH); // turn the pullup for SENSORPIN1 on

  pinMode(SENSORPIN2, INPUT); // initiate SENSORPIN2 as an input
  digitalWrite(SENSORPIN2, HIGH); // turn the pullup for SENSORPIN2 on

  lcd.begin(16, 2); // set up the LCDs number of columns and rows:
  setupScreen(); // Print a message to the LCD.

  music.speakerPin = 9; // set speaker output as pin 9
}

void setupScreen() // what appears on the LCD screen at start
{
  lcd.clear(); // clear LCD screen
  lcd.setCursor(0, 0); // set cursor position for LCD screen
  lcd.print("FRANCE v GERMANY"); // what to display at start

  HomeScore = 0; // value for HomeScore variable
  AwayScore = 0; // value for AwayScore variable
}

void loop() {

  sensorState1 = digitalRead(SENSORPIN1); // tells arduino to get the value of sensorState1 by reading SENSORPIN1

  if (sensorState1 == LOW) { // if the value is LOW (broken) then...
    HomeScore++; // advance Home Score by 1 pt
    delay(500); // delay to prevent multiple scoring
    music.play("test.wav"); // play file from SD card
  }

  sensorState2 = digitalRead(SENSORPIN2); // tells arduino to get the value of sensorState2 by reading SENSORPIN2

  if (sensorState2 == LOW) {
    HomeScore++;
    delay(500);
  }

  {
    lcd.setCursor(2, 1); // set the cursor position for the Home Score
    lcd.print(HomeScore); // print the HomeScore variable
    lcd.setCursor(12, 1); // set the cursor position for the Away Score
    lcd.print(AwayScore); // print the AwayScore

  }
}

Notice how much easier it is to read, with auto formatting.

I think the visiting team might be angry that all their points go to the home team. :slight_smile:

Can you post the sketch that did play sound?

1 Like