//static char *phone_numbers[] = {
static const char* const phone_numbers[] = {
"86667771122",
"1684",
"1",
"999",
"0",
"000",
"54321",
NULL,
};
#define FPSTR(pstr) (const __FlashStringHelper*)(pstr)
// https://alexgyver.ru/lessons/progmem/ есть ошибки
//https://microsin.net/programming/avr/avrstudio-gcc-progmem.html
const char str1[] PROGMEM = "86667771122";
const char str2[] PROGMEM = "1684";
const char str3[] PROGMEM = "0";
const char str4[] PROGMEM = "54321";
static const char* const phone_numPGM[] PROGMEM = {
str1, str2, str3, str4,
NULL,
};
volatile int vInt;
void setup() {
Serial.begin(9600);
Serial.setTimeout(10);
Serial.println("===START===");
// Проверка, что чтение из FLASH доступно с разным синтаксисом
vInt = 0;
Serial.println(FPSTR((PGM_P)pgm_read_ptr(&phone_numPGM[vInt])));
vInt = 1;
char buf_list[20];
strcpy_P(buf_list, (PGM_P)pgm_read_ptr(&phone_numPGM[vInt]));
Serial.println(buf_list); // 1684
vInt = 2;
strcpy_P(buf_list, pgm_read_ptr(&phone_numPGM[vInt]));
Serial.println(buf_list); // 0
}
void loop() {
if (Serial.available()) {
String inStr = Serial.readString(); // Считываем строку (число) для поиска
inStr.trim();
if (inStr.length() > 0) {
if (has_number(inStr.c_str()))
Serial.println("GET");
if (has_number_PGM(inStr.c_str()))
Serial.println("GET PGM");
}
}
}
static bool has_number(const char *num) {
int i = 0;
if (num && *num)
while (phone_numbers[i])
if (!strcmp(phone_numbers[i++], num))
return true;
return false;
}
static bool has_number_PGM(const char *num) {
int i = 0;
if (num && *num)
while (auto tmpPtr = (PGM_P)pgm_read_ptr(&phone_numPGM[i++]))
if (!strcmp_P(num, tmpPtr))
return true;
return false;
}
WOKWI