using buttons like serial command inputs

Hello everyone

I´m trying to use these ph calibration code, but instead of inserting via serial the "CALIBRATION" or "EXIT" or "ACID:xx" or "ALKALI:xx" commands, what i want is to insert these commands with buttons, if i press button 1 , it enters "CALIBRATION" command, if i press button 2 it inserts predefined "ACID: 4.0" command....

The button libraries is not a problem for me, but i don´t know how to simulate the manual introduction of the commands in the serial with buttons.

Thank you very much!!!!

phcalib.ino.ino (8.18 KB)

This function in your program seems to be the part that interprets the Serial messages

byte uartParse()
{
  byte modeIndex = 0;
  if(strstr(receivedBuffer, "CALIBRATION") != NULL) 
      modeIndex = 1;
  else if(strstr(receivedBuffer, "EXIT") != NULL) 
      modeIndex = 4;
  else if(strstr(receivedBuffer, "ACID:") != NULL)   
      modeIndex = 2;  
  else if(strstr(receivedBuffer, "ALKALI:") != NULL)
      modeIndex = 3;
  return modeIndex;
}

and it seems to be called with this line of code

byte modeIndex = uartParse();

I reckon if you create an equivalent function that produces the same output when a button is pressed and call it like this

byte modeIndex = getKeypadValueConvertedToMode();

you will get the same functionality.

if you want to be able to use Serial and the keypad in the same program things will be a little more complex because you will need code to decide which to use.

...R

if you want to be able to use Serial and the keypad in the same program things will be a little more complex because you will need code to decide which to use.

I don't see why anything like that would be necessary. If the "acid" switch is pressed, the code that detects that could simply set receivedBuffer to "ACID:xx" (where xx is the appropriate value), and then call uartParse() and do the same thing(s) with the return value that the current code does.

PaulS:
I don't see why anything like that would be necessary. If the "acid" switch is pressed, the code that detects that could simply set receivedBuffer to "ACID:xx" (where xx is the appropriate value), and then call uartParse() and do the same thing(s) with the return value that the current code does.

But what happens if a message also arrives by Serial?

...R

Robin2:
But what happens if a message also arrives by Serial?

...R

I'm assuming that OP probably knows not to push a button while in the middle of sending serial data. I could be wrong.