Note that there are some explanatory texts on larger screens.

plurals
  1. POvariables value unexpectedly changes?
    primarykey
    data
    text
    <p>The program below uses a keypad and arduino to test whether an input is equal to the password. Whenever '#' is pressed the input is checked and then the variable storing the input resets to an empty string (char input[257] = ""). The program then loops back to the beginning of the void loop() code block. I am having a problem when my program loops back to the beginning of the "void loop()" code block. When i reset input to an empty string, input is reset to an empty string as it should. However, when the program loops the value of input is changed to what it was before. So if i originally entered "123abc" and hit '#' the program would tell me that the input was incorrect and then the program would reset the variable to an empty string, but when the program loops the variable storing the empty string is changed back to "123abc". What's happening? Why doesn't the variable remain an empty string? </p> <pre><code>#include &lt;Keypad.h&gt; const byte ROWS = 4; //four rows const byte COLS = 4; //three columns char keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad char password[9] = "3994A", input[257]=""; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); int x; void setup(){ Serial.begin(9600); } void loop(){ x = 0; Serial.println(input); while (1) { char key = keypad.getKey(); if (key) { if (key == '#') { break; } input[x] = key; x+=1; } } if (strcmp(password,input) == 0) {Serial.println("Access Granted"); } else {Serial.println("Access Denied"); } char input[257] = ""; Serial.println(input); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload