Ha ha, my english is not very good, sorry. By the way, i know you, your knowledge is very good.
In my micro SD card product, the shield has a regulator chip for all lines, so i don't need a level shifter, I'm sure, otherwise, TMRpcm did not work but did.
This is my whole code, maybe you can help. (tmrpcm.play is in buttonstate line)
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 53 //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h> // also need to include this library...
#include <SPI.h>
TMRpcm tmrpcm; // create an object for use in this sketch
#include <Servo.h>
int aci=90,i;
Servo myservo;
int gecikme=40;
HardwareSerial &Bluetooth = Serial1;
// Variables used for incoming data
const byte maxDataLength = 20;
char receivedChars[21] ;
boolean newData = false;
// Pins de HC-SR04
const int trigger_sol = 33;
const int echo_sol = 35;
// Pins de HC-SR04
const int trigger_sag = 37;
const int echo_sag = 39;
// Constants for hardware
const byte m_PIN[] = {23,25,27,29};
boolean m_State[] = {false,false,false,false};
const int on_sol = 22;
const int on_orta = 24;
const int on_sag = 26;
const int hareket_sensoru_sol = 38;
const int hareket_sensoru_sag = 40;
int durum;
int engel_oku1;
int engel_oku2;
int engel_oku3;
void setup() {
Serial.begin(9600);
myservo.attach(10);
// Configuración de los pines
pinMode(trigger_sol, OUTPUT);
pinMode(echo_sol, INPUT);
pinMode(trigger_sag, OUTPUT);
pinMode(echo_sag, INPUT);
//Engel switchler pull-up olacak
for (byte pin = 0; pin < 4; pin++)
{
pinMode(m_PIN[pin], OUTPUT); digitalWrite(m_PIN[pin],LOW);
}
pinMode(22,INPUT_PULLUP); // on_sol
pinMode(24,INPUT_PULLUP); //on_orta
pinMode(26,INPUT_PULLUP);
pinMode(38,INPUT);
pinMode(40,INPUT);
kafa_test();
ileri_git(); delay(1000);dur();
geri_git(); delay(200);dur();
sola_don(); delay(200);dur();
saga_don(); delay(200);dur();
// open serial communication for debugging
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
// open software serial connection to the Bluetooth module.
Bluetooth.begin(9600);
Serial.println("Serial started at 9600");
newData = false;
{
tmrpcm.speakerPin = 46; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
}
}
//***********************************************************
void loop() {
{engel_oku1 = digitalRead(22);
if (engel_oku1 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,3,1>" );Bluetooth.print("<L,4,0>" );
digitalWrite(23,LOW);digitalWrite(25, HIGH);digitalWrite(27, LOW);digitalWrite(29, HIGH);sistem_test();dur();Bluetooth.print("<L,3,0>" );}
}
{engel_oku2 = digitalRead(24);
if (engel_oku2 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,1>" );Bluetooth.print("<L,3,0>" );Bluetooth.print("<L,4,0>" );
digitalWrite(23,LOW);digitalWrite(25, HIGH);digitalWrite(27, HIGH);digitalWrite(29, LOW);sistem_test();dur();Bluetooth.print("<L,2,0>" );}
}
{engel_oku3 = digitalRead(26);
if (engel_oku3 == LOW) {Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,3,0>" );Bluetooth.print("<L,4,1>" );
digitalWrite(23,HIGH);digitalWrite(25, LOW);digitalWrite(27,HIGH);digitalWrite(29, LOW);sistem_test();dur();Bluetooth.print("<L,4,0>" );}
}
recvWithStartEndMarkers(); // check to see if we have received any new commands
if (newData) { processCommand(); } // if we have a new command do something about it
{ Serial.println(" Hareket Kontrol Ediliyor ");
int buttonState_sol = digitalRead(38);
int buttonState_sag = digitalRead(40);
if (buttonState_sol == LOW) {Serial.println(" SOLDA ENGEL ");
Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,3,1>");Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,4,0>" );tmrpcm.play("kayra.wav");
digitalWrite(25, HIGH);digitalWrite(29, HIGH);digitalWrite(23, LOW);digitalWrite(27, LOW);
delay(2000);sistem_test();dur();Bluetooth.print("<L,3,0>");}
else if(buttonState_sag == LOW)
{ Serial.println(" SAGDA ENGEL ");
Bluetooth.print("<L,2,0>" );Bluetooth.print("<L,4,1>" );Bluetooth.print("<L,1,0>" );Bluetooth.print("<L,3,0>");tmrpcm.play("kayra.wav");
digitalWrite(23, HIGH);digitalWrite(27, HIGH);digitalWrite(25, LOW);digitalWrite(29, LOW);delay(2000);sistem_test();dur();Bluetooth.print("<L,4,0>");}
}
}
//***********************************************************
//***********************************************************
//***********************************************************
//***********************************************************
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
void sola_don() // sola dön
{
digitalWrite(23, HIGH);digitalWrite(27, HIGH); delay(100);Serial.println(" SOLA donuyorum "); durum=1;
}
void saga_don()
{
digitalWrite(25, HIGH);digitalWrite(29, HIGH); delay(100); Serial.println(" SAGA donuyorum ");durum=1;
}
void ileri_git() // geri git
{
digitalWrite(23, HIGH);digitalWrite(29, HIGH); delay(100);Serial.println(" ilerliyorum ");durum=1;
}
void geri_git() // ileri olacak
{
digitalWrite(25, HIGH);digitalWrite(27, HIGH); delay(100);Serial.println(" GERi Gidiyorum ");durum=1;
}
void dur()
{
digitalWrite(23, LOW);
digitalWrite(25, LOW);
digitalWrite(27, LOW);
digitalWrite(29, LOW);
delay(500); Serial.println(" DURDUM ");
}
//*******************************************************//
void kafa_test()
{
for(i=1;i<=15;i=i+1)
{
aci=aci+5;
myservo.write(aci);
// sets the servo position according to the scaled value
delay(gecikme);
}
Serial.print("1= "); Serial.println(aci); delay(500);
for(i=1;i<=30;i=i+1)
{
aci=aci-5;
myservo.write(aci);
delay(gecikme);
}
Serial.print("2= "); Serial.println(aci); delay(500);
for(i=1;i<=15;i=i+1)
{
aci=aci+5;
myservo.write(aci);
// sets the servo position according to the scaled value
delay(gecikme);
}
Serial.print("3: "); Serial.println(aci); delay(500);
delay(2000);
}
void processCommand()
{
Serial.print("receivedChars = "); Serial.println(receivedChars);
if (receivedChars[0] == 'L')
{
byte mnum = receivedChars[1] - 48; // convert ascii to value by subtracting 48
boolean mstatus = receivedChars[2] - 48;
digitalWrite(m_PIN[mnum-1],mstatus);
m_State[mnum-1] = mstatus;
}
receivedChars[0] = '\0';
newData = false;
}
void sistem_test()
{
for(i=1;i<=5;i=i+1)
{
aci=aci+5;
myservo.write(aci);
// sets the servo position according to the scaled value
delay(gecikme);
}
Serial.print("test1= "); Serial.println(aci); delay(500);
for(i=1;i<=5;i=i+1)
{
aci=aci-5;
myservo.write(aci);
delay(gecikme);
}
Serial.print("test2= "); Serial.println(aci); delay(500);
}
void recvWithStartEndMarkers()
{
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
if (Bluetooth.available() > 0)
{
rc = Bluetooth.read();
if (recvInProgress == true)
{
if (rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if (ndx > maxDataLength) { ndx = maxDataLength; }
}
else
{
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) { recvInProgress = true; }
}
}