This program I wrote earlier this year was working fine, now I keep getting this warning:
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("caillou_0.wav");
Since this is a warning and not necessarily an error, I don't know if it is the reason the program no longer works.
The files are all saved on a microSD card as smaller files 8 bit 16000 sample rate mono files.
The complete code is here:
#include "SD.h" //need to include the SD library
#define SD_ChipSelectPin 4 //using digital pin 4 o n arduino UNO
#include "TMRpcm.h" //also need to include this library
#include "SPI.h"
TMRpcm tmrpcm;
int switchPin1 = 2; // the pin where the NO switch will be wired
int switchPin2 = 3; // the pin where the NO switch will be wired
int switchPin3 = 10; // the pin to read if ignition is fully on
int switchPin4 = A0; //the pin to read if sound button is pushed
//int switchPin5 = 10; // the pin to read if sound is pushed
int led1 = 6; //the led that will be lit by the NC switch
int led2 = 7; // the led that will be lit by the NO switch
int led3 = 8; //blue led
int switchState1 = 0; //the state of the NC switch
int switchState2 = 0; //the state of the NO switch
int switchState3 = 0; //the state of the ignition switch
int switchState4 = 0; // the state of the Siren Switch
int switchState5 = 0; // the state of other siren switch
void setup() {
// put your setup code here, to run once:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(switchPin1, INPUT_PULLUP);
pinMode(switchPin2, INPUT_PULLUP);
pinMode(switchPin3, INPUT_PULLUP);
pinMode(switchPin4, INPUT_PULLUP);
// pinMode(switchPin5, INPUT);
tmrpcm.speakerPin = 9;
if (!SD.begin(SD_ChipSelectPin)) { //see if the card is present and can be initialized:
return; //don't do anything more if not
}
tmrpcm.volume(5);
tmrpcm.play("peppa_pig.wav"); //the sound file will play each time the arduino powers up or is reset
}
void loop() {
// put your main code here, to run repeatedly:
switchState1 = digitalRead(switchPin1);
switchState2 = digitalRead(switchPin2);
switchState3 = digitalRead(switchPin3);
switchState4 = digitalRead(switchPin4);
// switchState5 = digitalRead(switchPin5);
{
if (switchState1 == LOW) { //if switch is pushed
tmrpcm.play("peppa_pig.wav");
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW) ;
delay(1000);
}
if (switchState2 == LOW) { //if switch is pushed
tmrpcm.play("caillou_0.wav");
digitalWrite(led2, HIGH);
digitalWrite(led1, LOW);
delay(1000);}
if (switchState3 == LOW) {//if sw3 is pushed then play "2.wav"
tmrpcm.play("blaze_horn.wav");
for (int j=1; j<=160; j=j+1) {digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(100);
digitalWrite(led1, LOW);
digitalWrite(led3, HIGH);
delay(100);
}
digitalWrite(led1, LOW);
digitalWrite(led3, LOW);
}
if (switchState4 == LOW) {//if sw4 is pushed play "3.wav"
tmrpcm.play("pj_masks_theme.wav");
for (int k=1; k<=35; k=k+1) {digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(200);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(200);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(200);
}
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
}
}