abh*_*ato -1 arduino dynamic-arrays
我正在尝试编写一个代码,当给出正确的密码时可以打开门。但是,在这样做的过程中,我遇到了一个问题。我必须将输入的密码存储在动态数组中。我知道有一个用于制作动态数组的包,但我不知道制作动态数组的代码。我发布了到目前为止我所做的代码,即仅启动键盘。
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 8, 7, 6, 9 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
}
Run Code Online (Sandbox Code Playgroud)
小智 6
int* dynamicArray;
dynamicArray = new int[arraySize];
if(dynamicArray == nullptr) {
//if memory could not be assigned
}
//do stuff with your array
delete[] dynamicArray; //delete when not in use anymore
Run Code Online (Sandbox Code Playgroud)