Trying to make a program that plays a bird call from a SD card. then shows you the Name of bird from SD card. it will not work without a delay. it will not work with a bird call only a simple wave playing. Any suggestion. was thinking get Name from sd card first then display after sound. but cannot get it to work. any help would be great. I am not good at programing and just try to get things to work.
/* Needs to be wav, bits 8, hz 16000, mono
1horn
3
4
5 Saddle back
6 LSK F
7 LSK M
8 Hihi
//Arduino Uno I2C module LCD
//GND - GND
//5V - Vcc
//Analog Pin 4 - SDA
//Analog pin 5 - SCL
SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
Pin 2 used here for consistency with other Arduino examples
*/
//LCD liberys
#include <Wire.h> // this replaces all stuff if no module
#include <LiquidCrystal_I2C.h> // this replaces all stuff if no module
LiquidCrystal_I2C lcd(0x27, 16, 2); // this replaces all stuff if no module
//SD card liburays
#include <SD.h>
// wave file playing libery
#include <TMRpcm.h>
TMRpcm tmrpcm; // create an object for use in this sketch
#include <SPI.h>
const int chipSelect = 2; // for sd connection
int SW1; //the bottom pushed value. asign a button to each one in loop
int SW2;
int SW3;
int SW4;
void setup() {
//configure pin to input and enable the internal pull-up resistor
pinMode(5, INPUT_PULLUP); //Botton D5 and GRD for botton
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
tmrpcm.speakerPin = 3; //speacker pin was 10 had to change to 3
lcd.begin(); // this replaces all stuff if no module
lcd.backlight(); // this replaces all stuff if no module
lcd.clear(); // this replaces all stuff if no module
lcd.setCursor(1, 0);
lcd.print("Bruce Harrison");
lcd.setCursor(1, 1);
lcd.print("* Bird Game *");
delay(500);
lcd.noDisplay(); // Turn off the display:
delay(500);
lcd.display(); // Turn on the display:
delay(500);
lcd.clear(); // this replaces all stuff if no module
////////// added everything in here
Serial.begin(9600); // Open serial communications and wait for port to open:
while (!Serial)
; // wait for Serial Monitor to connect. Needed for native USB port boards only:
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) { // trying thing
Serial.println("initialization failed. Things to check:");
Serial.println("1. is a card inserted?");
Serial.println("2. is your wiring correct?");
Serial.println("3. did you change the chipSelect pin to match your shield or module?");
Serial.println("Note: press reset or reopen this serial monitor after fixing your issue!");
while (true)
;
}
Serial.println("initialization done.");
/////play horn to see if it works
if (!SD.begin(chipSelect)) {
return; // don't do anything more if not
}
tmrpcm.volume(1);
tmrpcm.play("1.wav"); //the sound file "1" will play each time the arduino powers up, or is reset
delay(4000);
/////////// Writing the file on serail monitor
File dataFile = SD.open("2e.txt"); // open the file, only one can be open at a time, so have to close after
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read());
}
} else {
Serial.println("error opening datalog.txt"); // if the file isn't open, pop up an error:
}
dataFile.close();
//////////////////////////////////////////////////////////////////////////////////////////////////////
// area for LCD stuff
{
File dataFile = SD.open("2e.txt");
lcd.setCursor(3, 0); // this puts everything on same spot
while (dataFile.available()) {
char c = dataFile.read(); //this is the file from SD card
lcd.print(c); // this prints the data file 1 letter at a time. one after the other
delay(50); // how farst it prints the letter
}
}
dataFile.close(); // closing eng txt file
{
File dataFile = SD.open("2m.txt");
lcd.setCursor(3, 1); // this puts everything on same spot
while (dataFile.available()) {
char c = dataFile.read(); //this is the file from SD card
lcd.print(c); // this prints the data file 1 letter at a time. one after the other
delay(50); // how farst it prints the letter
}
}
dataFile.close(); // closing ma txt file
}
void loop() {
}