• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
password.h
#4
Dlaczego podczas wgrywania tego kodu pojawia się takie ostrzeżenie? 

Kod:
#include <Keypad.h>
#include <Password.h>

String newPasswordString; //hold the new password
char newPassword[6]; //charater string of newPasswordString

//initialize password to 1234
//you can use password.set(newPassword) to overwrite it
Password password = Password( "1234" );

byte maxPasswordLength = 6;
byte currentPasswordLength = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four 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] = {6,7,8,9}; //connect to row pinouts

// Connect keypad COL0, COL1, COL2 and COL3 to these Arduino pins.
byte colPins[COLS] = {2,3,4,5}; //connect to column pinouts

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

void setup(){
   Serial.begin(9600);
}

void loop(){
   char key = keypad.getKey();
   if (key != NO_KEY){
      delay(60);
      switch (key){
      case 'A': break;
      case 'B': break;
      case 'C': break;
      case 'D': changePassword(); break;
      case '#': checkPassword(); break;
      case '*': resetPassword(); break;
      default: processNumberKey(key);
      }
   }
}

void processNumberKey(char key) {
   Serial.print(key);
   currentPasswordLength++;
   password.append(key);
   if (currentPasswordLength == maxPasswordLength) {
      checkPassword();
   }
}

void checkPassword() {
   if (password.evaluate()){
      Serial.println(" OK.");
   } else {
      Serial.println(" Wrong passwowrd!");
   }
   resetPassword();
}

void resetPassword() {
   password.reset();
   currentPasswordLength = 0;
}

void changePassword() {
   newPasswordString = Password();
   newPasswordString.toCharArray(newPassword, newPasswordString.length()+1); //convert string to char array
password.set(newPassword);
   resetPassword();
   Serial.print("Password changed to ");
   Serial.println(newPasswordString);
}


String Password()
{
    String password = "";
    while(1){
        char key = keypad.getKey();
        if (key){
                       
                if ((key=='0') || (key=='1') || (key=='2') ||
                    (key=='3') || (key=='4') || (key=='5') ||
                    (key=='6') || (key=='7') || (key=='8') ||
                    (key=='9')) // jesli wcisnąłem klawisze 0 - 9
                    {
                        password = password + key;// taka konkatenacja, to tylko w Adruino zadziała
                    }

                    if (key=='#') break;// zatwierdzamy wybór
           
                }
    }
    return password;
}


"C:\Users\Pawel\Desktop\ostatnia_wersja.ino:9:38: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

Password password = Password( "1234" );

                                      ^

Szkic używa 5472 bajtów (17%) pamięci programu. Maksimum to 30720 bajtów.
Zmienne globalne używają 427 bajtów (20%) pamięci dynamicznej, pozostawiając 1621 bajtów dla zmiennych lokalnych. Maksimum to 2048 bajtów."

Nie wiem czy ma to znaczenie ale używam arduino idee 1.8.11

Edit.

Doszedłem o co biega. Linijkę Password password = Password( "1234" ); musiałem zmienić na Password password = Password( (char*)"1234" );
 
Odpowiedź
  


Wiadomości w tym wątku
password.h - przez pawel296 - 07-02-2020, 15:17
RE: password.h - przez Robson Kerman - 07-02-2020, 23:48
RE: password.h - przez pawel296 - 08-02-2020, 23:42
RE: password.h - przez pawel296 - 09-02-2020, 14:54

Skocz do:


Przeglądający: 1 gości