I am trying to be a good programmer and learn to not use the String class.
Mostly out of necessity because my current project is using a lot of RAM in Strings.
Background, and why I didn't post my whole sketch.
I have an old-style rotary telephone dial with a Wemos D1 Mini counting the pulses then sending the dialed number to an Arduino Uno over I2C. In my original sketch, dialedNumber was initialized as a String. And the sketch works. But I need to free up more RAM - thus I am trying to convert my Strings to strings. If you need to see the whole sketch, I will post it, but it is pretty big.
In the code segment below, the receiveEvent function receives the characters dialed and the numbers accumulate in the char array dialedNumber.
When I dial "01", dialedNumber contains "01" terminated with '\0'.
My problem is how to use strcmp() in the function processDialedNumber().
I have tried
if (strcmp(dialedNumber, "03")) return 3;
if (strcmp(&dialedNumber, "03")) return 3;
if (strcmp(*dialedNumber, "03")) return 3;
but they all return 1, where I should get 3.
I am certain that the pointer to dialedNumber array is my problem, but I can't figure out what I am doing wrong.
Any tips would be appreciated.
Here's the functions inivolved:
char dialedNumber[11] = {0}; //The phone number string from the dialer
int soundIndex; //Index of the sound file
//---------------------- processDialedNumber() ----------------------
int processDialedNumber() {
//Handle the phone number string received from the dialer (I2C Master).
if (strcmp(dialedNumber[0], "01")) return 1;
if (strcmp(dialedNumber[0], "02")) return 2;
if (strcmp(dialedNumber[0], "03")) return 3;
if (strcmp(dialedNumber[0], "04")) return 4;
if (strcmp(dialedNumber[0], "05")) return 5;
}
//---------------------- receiveEvent() ----------------------
// function that executes whenever data is received from master
void receiveEvent(int howMany) {
byte i = 0;
char c;
while (0 < Wire.available()) {
c = Wire.read(); //receive byte as a character
dialedNumber[i++] = c;
}
dialedNumber[i] = '\0'; //Terminate the accumulated string
soundIndex = processDialedNumber();
Serial.println();
Serial.print(F("dialed= "));
Serial.println(dialedNumber);
Serial.print(F("soundIndex= "));
Serial.println(soundIndex);
dialedNumber[0] = '\0'; //Ready for the next number..
}