warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-string

When I run this code in another pc , worked well . But same code occurs this error :

C:\Users\berkc\Desktop\sketch_dec16a\sketch_dec16a.ino: In function ‘void mode_learn()’:

C:\Users\berkc\Desktop\sketch_dec16a\sketch_dec16a.ino:36:29: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

tmrpcm.play(“colorRed.wav”); //Play music file

^

C:\Users\berkc\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp: In member function ‘byte TMRpcm::metaInfo(boolean, char*, char*, byte)’:

C:\Users\berkc\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1381:18: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

char* datStr = “LIST”;

And the code is :

#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 <Button.h>
#include <TMRpcm.h>           //  also need to include this library...
#include <SPI.h>

int  buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int counter=0;
TMRpcm tmrpcm;   // create an object for use in this sketch

void setup(){
  pinMode(9,INPUT);
  pinMode(10,INPUT);
 
  tmrpcm.speakerPin = 46; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
  tmrpcm.setVolume(6);

    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 mode_quiz(){
   if(buttonState1 == HIGH && tmrpcm.isPlaying()== false){ 
  tmrpcm.play("test.wav"); //Play music file
   Serial.println("button 2 pressed");
  }
}
void mode_learn(){  
  if(buttonState1 == HIGH &&  tmrpcm.isPlaying()== false){ 
  tmrpcm.play("colorRed.wav"); //Play music file
  Serial.println("button 1 pressed");
}
}
void loop(){  
  buttonState1 = digitalRead(9);
  buttonState2 = digitalRead(10);
  buttonState3 = digitalRead(11);
  if(buttonState2 == HIGH){
    counter++;
  }
  if(counter%2==0){
    mode_quiz();
    Serial.println("mode quız");
    delay(300);
  }
  else{
    mode_learn();
    Serial.println("mode learn");
    delay(300);
    }

}

Is there anyone can help me ?

Try this:

tmrpcm.play((char *)"colorRed.wav");

ToddL1962:
Try this:

tmrpcm.play((char *)"colorRed.wav");

It should be noted that this is in general a very bad idea.
In this case, however, there is a known bug in the tmrpcm library, and it is known that it doesn't write to the parameter, so casting away the const is not a problem here.

The clean solution is to change the parameter of the "play" function by editing the library source files.

Pieter

PieterP:
It should be noted that this is in general a very bad idea.
In this case, however, there is a known bug in the tmrpcm library, and it is known that it doesn’t write to the parameter, so casting away the const is not a problem here.

The clean solution is to change the parameter of the “play” function by editing the library source files.

Pieter

You are absolutely correct Pieter and I should have pointed that out. It should be a const argument in the library function. Furthermore, the compiler forces you to cast it as sort of an acknowledgement that you are “aware” of what you are doing. Casting

It's a warning, not an error.

It depends on the compiler version and / or compiler settings if the warning shows or not. Compare file -> preferences -> compiler warnings on the two machines