Write button inputs to array - Help needed

I have a sketch that outputs different sensor values constantly and this should continue uninterrupted. I have an input from a touchscreen (like a keypad) where the user can set a new trigger value for one of the sensors. So he will choose a sensor which sets a flag (buttonInput =1) and when this button is set, he can set a new 2 digit trigger value (keyInput).
Problem is the keypad sends the values in 1 character at a time and after the first character there may be several sensor outputs written (loops through the code) before the next keyInput arrives.

i understand that i could use a for-next loop to stop the main loop and wait for the 2 inputs sequentially, write them to an array and continue with the main loop, but I dont want to interrupt the main loop as the sensor values go to a plot file.

I need this 2 digit value to be saved as a number meaning -
key[0] = 8
key[1] = 3
keyValue = 83 which will be the new trigger value.

Attached is the serial monitor output which shows various sensor values written and then buttonInput is set to 1. In between some more sensor values are keyInput values which should be written to key[0] and key[1] respectively, or some other way of turning the 2 inputs into an integer value. If required, the key sequence can be ended by * or whatever else is required.

Any help to structure this in the most efficient way is appreciated.

buttonInput = 0
30.00
29.46
10.05
29.84
28.75
30.00
29.46
10.05
29.84
28.75
buttonInput = 1
30.00
29.43
10.02
29.84
28.75
Key input = 8
31.00
29.38
10.47
29.84
28.75
31.00
29.35
10.44
29.85
28.75
Key input = 3
31.00
29.32
10.42
29.85
28.75
Key input = *
31.00
29.30
10.40
29.84
28.75
buttonInput = 0
31.00
29.31
10.41
29.84
28.75

I think what you would want to do is that when a keypad is pressed, goto a routine that set keypad1 value = the character. and sets a timer to the current millis.

when another key is pressed if it is within an alloted amount of time then goto a 2nd routine otherwise goto the first routine.

This way if a key is pressed and it is the wrong key, the person can wait till it times out and then put the first key in again and it will allow your current code to keep running until the 2nd key is pressed.

Jasit

What @jasit says sounds sensible.

There isn't much point showing us the output without showing us the code that produces it.

Is your code designed so it can read the buttons interspersed with reading the sensors and sending out the results?

...R

Is your code designed so it can read the buttons interspersed with reading the sensors and sending out the results?

Yes, I am using 4D Systems Libraries and event handlers so the code would not be useful as you cant run it unless you have a device, and all it outputs is the buttonInput flag and the keyInput values in amongst all the sensor values. I dont care about the timing because that is handled in the touchscreen. I just need to capture the buttonInput values to an array.

As an example, see this basic code. It just simulates a loop with 2 keyInput values arriving at different times.
The array starts with values of 2,4. after 10 loops, the key[0] value changes to 8 and after another 10 loops, key[2] changes to 3.
Ignore the count and IF statements as they are just there for control in this example.

I need a better way to recognize that after the buttonInput flag is set, the first keyInput value seen should be written to key[0] and the 2nd one should be written to key[1]
Then how write those values to variable as 1 number 83.

I have probably been staring at it too long.
Thanks

int buttonInput = 1;
int key[3] = {2,4};
int keyInput;
int count = 0;

void setup() {
  Serial.begin(115200);      
}

void loop() {
  Serial.println("output");
  
  if (count > 10)
  { 
    keyInput = 8;
    key[0] = keyInput;
  }
  if (count > 20)
  {
    keyInput = 3;
    key[1] = keyInput;
  }   
  if (count >25)
  {
    buttonInput = 0;
  }
  Serial.println(key[0]);
  Serial.println(key[1]);
  
  if (buttonInput == 0)
  {
    Serial.println ("send to trigger");
  }
  count = count + 1;
   delay(500); 
}

K, where do you reset count back down to zero?

Ignore the count and IF statements as they are just there for control in this example.

I understand the problem of not being able to run the code without your hardware. But the problem is that you haven't told us (or shown us) how the values you want to save are represented within your program.

Post the full code and tell us where the relevant pieces are.

...R