receiving error: warning: ISO C++ forbids converting a string constant to 'char*

Hi,

real arduino beginner here, someone else compiled this code for me for a button activated circuit that turns on leds, has a colour change at time intervals and activates sound effects running on an Adafruit Waveshield. I can’t get hold of the original code writer and when I verify it through the IDE I receive the following errors:

In file included from /Users/dangudgeon/Documents/Arduino/sketch_jun12b/sketch_jun12b.ino:4:0:
/Users/dangudgeon/Documents/Arduino/libraries/AF_Wave/util.h:3:0: warning: "UINT16_MAX" redefined
 #define UINT16_MAX 65535U

 ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/lib/gcc/avr/5.4.0/include/stdint.h:9:0,
                 from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/inttypes.h:37,
                 from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/pgmspace.h:88,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:28,
                 from sketch/sketch_jun12b.ino.cpp:1:
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/stdint.h:346:0: note: this is the location of the previous definition
 #define UINT16_MAX (__CONCAT(INT16_MAX, U) * 2U + 1U)
 ^
/Users/dangudgeon/Documents/Arduino/sketch_jun12b/sketch_jun12b.ino: In function 'void loop()':
/Users/dangudgeon/Documents/Arduino/sketch_jun12b/sketch_jun12b.ino:34:19: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
     playfile(SOUND);
                   ^

This is my code:

#include <Adafruit_NeoPixel.h>
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"

#define TIME 60000                     //60000 milli second = 60 seconds = 1 min

#define SOUND "Lakeside.WAV"              //Audio file name

#define Button 7
#define Led    8
#define LED_PIN    6
#define LED_COUNT 150

AF_Wave card;
File f;
Wavefile wave;
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

int start = 0;
int wasplaying = 0;
int i = 0;
int waitTime = TIME / 256;

void setup() {
  hardwareinit();
}

void loop() {
  if (digitalRead(Button) == LOW && start == 0) {
    start = 1;
    digitalWrite(Led , HIGH);
    playfile(SOUND);
    i = 0;
  }

  if (start == 1) {
    for ( ; i < 256 ; i++)
    {
      Serial.println(i);
      colorWipe(strip.Color(i, 255 - i, 255 - i), 50);

      if (digitalRead(Button) == HIGH)
        digitalWrite(Led , LOW);
      delay(waitTime);
    }
    start = 0;
  }
}

void hardwareinit() {
  Serial.begin(9600);
  strip.begin();
  strip.show();
  strip.setBrightness(90);

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  pinMode(Button , INPUT_PULLUP);
  pinMode(Led , OUTPUT);

  if (!card.init_card()) {
    putstring_nl("Card init. failed!"); return;
  }
  if (!card.open_partition()) {
    putstring_nl("No partition!"); return;
  }
  if (!card.open_filesys()) {
    putstring_nl("Couldn't open filesys"); return;
  }
  if (!card.open_rootdir()) {
    putstring_nl("Couldn't open dir"); return;
  }
  ls();
}

void colorWipe(uint32_t color, int wait) {
  for (int i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, color);
  }
  strip.show();
}

void ls() {
  char name[13];
  card.reset_dir();
  putstring_nl("Files found:");
  while (1) {
    if (!card.get_next_name_in_dir(name)) {
      card.reset_dir();
      return;
    }
    Serial.println(name);
  }
}

void playfile(char *name) {
  f = card.open_file(name);
  if (!f) {
    putstring_nl("Couldn't open file"); return;
  }
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  wave.play();
}

Trying to search the internet for answers but not having much luck.

My code knowledge is very basic and I really appreciate people’s patience

You need to understand the difference between warnings and errors. A warning is the compiler telling you there is something in the code that could possibly cause a problem but doesn't cause the compilation to fail. An error is a problem with the code that causes compilation to fail. In this case you have posted warnings, not errors.

You should always pay attention to warnings and fix them in your own code whenever possible. Unfortunately some library authors don't hold themselves to such high standards so sometimes you do just need to ignore a warning from a library that you didn't write. That can be quite annoying since you are always having to sort though a bunch of warnings in other people's sloppy code to make sure your own code is of high quality. You may decide it's worth editing the source of the library to fix the warning. If you do so, it's a good idea to submit a pull request for the fix to the library's repository to solve the problem upstream, otherwise the warnings will come back whenever you update to a new release of the library. This will also benefit all the other users of the library.

The final warning / error should be fixed by defining your 'playfile()' function as:

void playfile(const char *name) {

Thank you both, I will amend the file with the attached code, I tested the circuit and the LEDs work but I am not getting any sound from the Waveshield, when I place my finger on the metal component of the volume control I receive a buzzing noise. I have actually set up two circuits with this programming and I'm getting the same problem with both so I presume it is a programming issue?

Guys plsss i am working with school project and i cant run the program this is fhe error thank you

C:\Arduino\bem_program1\bem_program1.ino:5:39: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

Password password = Password ( "9534" );

Dionmar:
Guys plsss i am working with school project and i cant run the program this is fhe error thank you

C:\Arduino\bem_program1\bem_program1.ino:5:39: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

Password password = Password ( "9534" );

As I already explained above, this is a warning, not an error. If you don't know how to fix it, just ignore it. If you are getting an error, then you need to post the error.

Dionmar:
Guys plsss i am working with school project and i cant run the program this is fhe error thank you

C:\Arduino\bem_program1\bem_program1.ino:5:39: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

Password password = Password ( "9534" );

char myPassword[] = "9534";
Password password = Password(myPassword);

But it's just a warning, not an error. If your sketch is not complied or uploaded, you should read "How to use this forum" sticky note, and start a new thread.

There are two possibilities here: either the Password class has a bug, and should have a "const char *" parameter instead of "char *".
If that's not the case, then you are not allowed to pass a string literal to it, because it indicates that the password library will write to it.
You are not allowed to write to string literals, as mentioned by the warning.

Pieter