In your flow, everytime you press the inject button, you re-initilize the global variables. You should make that a separate flow.
You should also go read https://nodered.org/docs/user-guide/writing-functions#storing-data and then look at your last function
node again (it might help to read this thread too)