I tried everything. But I still need to learn a lot.
inputkeyboard is a global String
I enter a value on a 4x4 membrane keyboard
I decided to define the value as a sum of the day, month and year collected from the object created by the RTC (which does not appear in the code below)
The result is a 4-digit value, in today's case it is 2358
I need keyboard input to be equal to int calculodata so that it works when typing on the keyboard, which will reset ESP32
But I already used string(itoa(calculodata) and NumberToString(calculodata)
It does not work.
What is the simplest and easiest way to do this ?
int calculodata = now.Day()*now.Month()+now.Year();
Serial.print("fator data é: ");Serial.println(calculodata);
if (inputteclado == ?) {
delay(100);
ESP.restart(); // reseta o esp32
}
Yes, they will always be in the same place. These are numbers that I'm going to type on a 4x3 keyboard and I only need to get the 3rd and 4th or 4th. the 5th and the 6th. etc.
My first piece of advice would be to use C style strings rather than Strings
As they are of fixed length and place you can read each number string as it arrives and convert it to an int
If you really want to use Strings then you just need to use substring correctly to pick out the elements of the longer String like this
void setup()
{
Serial.begin(115200);
String wholeNumber = "123456789";
String one = wholeNumber.substring(4, 7); //567
Serial.println(one);
int oneInt = one.toInt();
Serial.println(oneInt * 2); //prove that it is an int
}
void loop()
{
}
Note that the substring end of range index is exclusive (ie not included in the returned string) and that character counting starts at zero, not 1