Go Down

Topic: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] (Read 760 times) previous topic - next topic

lluft1

Hello guys, I am pretty new with arduino and I downloaded a code tried to change the password and then I tried to run it but it showed an error:

Code: [Select]

C:\Users\Luigi Luft\AppData\Local\Temp\Rar$DIa0.283\keypad_password_servo\keypad_password_servo.ino:9:40: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

 Password password = Password( "148795" );//password to unlock box, can be changed

                                        ^


The code I downloaded:


Code: [Select]

#include <Password.h> //http://playground.arduino.cc/uploads/Code/Password.zip use password library
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip  //tells to use keypad library
#include <Servo.h> //tells to use servo library


Servo myservo; //declares servo
Password password = Password( "148795" );//password to unlock box, can be changed

const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 5, 4, 3, 2 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 8, 7, 6, 9 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  Serial.write(254);
  Serial.write(0x01);
  delay(200);
  pinMode(11, OUTPUT);  //green light
  pinMode(12, OUTPUT);  //red light
  myservo.attach(13); //servo on digital pin 9 //servo
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  }

void loop(){
  keypad.getKey();
  myservo.write(0);
  }
  //take care of some special events
  void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
 
  Serial.print("Enter: ");
  Serial.println(eKey);
  delay(10);
 
  Serial.write(254);
 
  switch (eKey){
    case 'A': checkPassword(); delay(1); break;
   
    case 'B': password.reset(); delay(1); break;
   
     default: password.append(eKey); delay(1);
}
}
}
void checkPassword(){
 
if (password.evaluate()){  //if password is right open box
   
    Serial.println("Accepted");
    Serial.write(254);delay(10);
    //Add code to run if it works
    myservo.write(5); //160deg
   
        digitalWrite(11, HIGH);//turn on
    delay(500); //wait 5 seconds
    digitalWrite(11, LOW);// turn off
   
   
}else{
    Serial.println("Denied"); //if passwords wrong keep box locked
    Serial.write(254);delay(10);
    //add code to run if it did not work
    myservo.write(0);
    digitalWrite(12, HIGH); //turn on
    delay(500); //wait 5 seconds
    digitalWrite(12, LOW);//turn off
   
}
}


can someone help me to figure this out?

pert

You need to understand the difference between warnings and errors. This is a warning, not an error. It's always a good idea to fix all the warnings you possibly can, which you can do in this case like this:
Code: [Select]
char myPassword[] = "148795";
Password password = Password(myPassword);//password to unlock box, can be changed

or by casting:
Code: [Select]
Password password = Password((char *)"148795");//password to unlock box, can be changed

Go Up