Small engine dyno need help to reset my counter after run

What does the comment on the second line of my function say?

line 2 msec

[{"id":"8583a880.175fd8","type":"inject","z":"c502d54b.368d98","name":"Sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":310,"y":300,"wires":[["12c451d2.0c1b5e"]]},{"id":"12c451d2.0c1b5e","type":"function","z":"c502d54b.368d98","name":"Count Revs","func":"// starts timing when counts reach low threshold\n// when high threshold is reached then passes on time difference in msec\n// Count can be reset by passing a message with topic \"reset\"\n// Set low and high thresholds by passing in topic of \"lowThreshold\" or \"highThreshold\"\n// with value in payload.\n// Any other topic is assumed to be a sensor input\n\nswitch(msg.topic) {\n    case \"reset\":\n        // reset counter\n        context.set(\"counter\", 0)\n        msg = null\n        break;\n        \n    case \"lowThreshold\":\n        context.set(\"lowThreshold\", msg.payload)\n        msg = null\n        break;\n        \n    case \"highThreshold\":\n        context.set(\"highThreshold\", msg.payload)\n        msg = null\n        break;\n        \n    default:\n        // sensor input\n        handleSensor()\n        break;\n}\nreturn msg\n\nfunction handleSensor() {\n    const lowThreshold = context.get(\"lowThreshold\")\n    const highThreshold = context.get(\"highThreshold\")\n    counter = context.get(\"counter\") || 0\n    counter++\n    if (counter == lowThreshold) {\n        // we have hit the first threshold, remember the current time in msec\n        const now = new Date().getTime()\n        context.set(\"startTime\", now)\n        node.warn(`startTime: ${now}`)\n        msg = null      // don't send anything\n    } else if (counter == highThreshold) {\n        const highNow = new Date().getTime()\n        // we have hit the second threshold, work out the time difference\n        msg.payload = highNow - context.get(\"startTime\")\n    } else {\n        // neither threshold so do nothing\n        msg = null\n    }\n    context.set(\"counter\", counter)\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":300,"wires":[["4ee39ede.8ba78","50cf5284.3f22ac"]]},{"id":"4ee39ede.8ba78","type":"debug","z":"c502d54b.368d98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":340,"wires":[]},{"id":"acc6affc.931e5","type":"inject","z":"c502d54b.368d98","name":"Clear counter","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","x":370,"y":20,"wires":[["12c451d2.0c1b5e"]]},{"id":"aeac78ed.2ba2b8","type":"inject","z":"c502d54b.368d98","name":"Set low threshold 3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lowThreshold","payload":"3","payloadType":"num","x":340,"y":120,"wires":[["12c451d2.0c1b5e"]]},{"id":"62f6b65a.24a0d8","type":"inject","z":"c502d54b.368d98","name":"Set high threshold 10","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"highThreshold","payload":"10","payloadType":"num","x":300,"y":200,"wires":[["12c451d2.0c1b5e"]]},{"id":"2d4bf090.c32f","type":"ui_gauge","z":"c502d54b.368d98","name":"","group":"5d511d53.994404","order":3,"width":"2","height":"2","gtype":"gage","title":"gauge","label":"deg c","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":860,"y":480,"wires":[]},{"id":"7d0425ab.6f341c","type":"ui_gauge","z":"c502d54b.368d98","name":"","group":"5d511d53.994404","order":1,"width":"2","height":"2","gtype":"gage","title":"gauge","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":850,"y":560,"wires":[]},{"id":"9f4b9f9e.69796","type":"rpi-gpio in","z":"c502d54b.368d98","name":"","pin":"11","intype":"tri","debounce":"25","read":false,"x":250,"y":360,"wires":[["12c451d2.0c1b5e"]]},{"id":"70ae121d.ffa51c","type":"inject","z":"c502d54b.368d98","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":480,"wires":[["bf3224a0.6e13b8"]]},{"id":"29d6f69c.5693ca","type":"function","z":"c502d54b.368d98","name":"Temperature","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":500,"wires":[["2d4bf090.c32f","61fbe8f9.9bddb8"]]},{"id":"49cb0622.1dd118","type":"function","z":"c502d54b.368d98","name":"Humidity","func":"msg.payload = msg.humidity\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":570,"y":560,"wires":[["7d0425ab.6f341c","22bcffa3.858d7"]]},{"id":"bf3224a0.6e13b8","type":"rpi-dht22","z":"c502d54b.368d98","name":"","topic":"rpi-dht22","dht":"11","pintype":"0","pin":4,"x":280,"y":480,"wires":[["29d6f69c.5693ca","49cb0622.1dd118"]]},{"id":"61fbe8f9.9bddb8","type":"debug","z":"c502d54b.368d98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":520,"wires":[]},{"id":"22bcffa3.858d7","type":"debug","z":"c502d54b.368d98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":620,"wires":[]},{"id":"50cf5284.3f22ac","type":"ui_gauge","z":"c502d54b.368d98","name":"","group":"9e96c901.0264f8","order":2,"width":"6","height":"6","gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"14000","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":820,"y":300,"wires":[]},{"id":"daa1a0cc.a072f","type":"ui_button","z":"c502d54b.368d98","name":"","group":"2c4c6cf8.d77924","order":1,"width":"3","height":"1","passthru":false,"label":"Start Run","tooltip":"","color":"","bgcolor":"","icon":"","payload":"reset","payloadType":"str","topic":"topic","topicType":"msg","x":400,"y":60,"wires":[["12c451d2.0c1b5e"]]},{"id":"3db7f87d.298758","type":"ui_button","z":"c502d54b.368d98","name":"","group":"d8c549ba.2c7f88","order":2,"width":"3","height":"1","passthru":false,"label":"Set Start RPM","tooltip":"","color":"","bgcolor":"","icon":"","payload":"setlowthreshold","payloadType":"str","topic":"topic","topicType":"msg","x":390,"y":160,"wires":[[]]},{"id":"9f265a39.9f3d88","type":"ui_button","z":"c502d54b.368d98","name":"","group":"d8c549ba.2c7f88","order":3,"width":"3","height":"1","passthru":false,"label":"Set Max RPM","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":360,"y":240,"wires":[[]]},{"id":"5d511d53.994404","type":"ui_group","name":"Weather","tab":"70eb2da0.452ad4","order":5,"disp":true,"width":"6","collapse":false},{"id":"9e96c901.0264f8","type":"ui_group","name":"DYNO","tab":"70eb2da0.452ad4","order":2,"disp":true,"width":"10","collapse":false},{"id":"2c4c6cf8.d77924","type":"ui_group","name":"Run Command","tab":"70eb2da0.452ad4","order":1,"disp":true,"width":"6","collapse":false},{"id":"d8c549ba.2c7f88","type":"ui_group","name":"SETUP","tab":"70eb2da0.452ad4","order":6,"disp":true,"width":"6","collapse":false},{"id":"70eb2da0.452ad4","type":"ui_tab","name":"LANGE RACING","icon":"dashboard","disabled":false,"hidden":false}]

What?
The second line of the function I exported is
// when high threshold is reached then passes on time difference in msec

yes line 2 high threshold = msec
I get it.
Can you open the flow i just sent?

Yes, why. What is the problem?

Sorry for my stupidity first node red project
On my dash board, I have added buttons. I would like to set set the values of Set start RPM and the Set Max RPM
Then press the Start Run button to reset counter and start the run.

Which bit isn't working?

Do you understand now why you got 1305 out of the function?

the run started with 3 counts. when it gets to 10 counts it captures the run time in msec 1305

So what isn't working for you?

it is working great, I'm trying to add functionality to the dashboard.
When you open the flow can you see the dashboard i have created?

To set the Start RPM and Max RPM i should use a text input, not a button? The variable would be lowThreshold and highThreshold

Yes, Text or Numeric, with the topic set (topic not variable).

However you are talking about RPM again. I presume the gpio is counting once for each turn on the engine, so it is counting total revolutions not speed. So the thresholds are the total number of times the engine has rotated, not how fast it is turning.

I pointed that out at the start but you said that was what you wanted, total number of turns not speed of rotation.

Yes you are correct. gpio will be counting once per revolution

So you don't want to time how long it takes to get from 3000 RPM to 13000 RPM, just how long it takes to count the next 10000 revolutions after has turned the first 3000 times?

The engine will be directly coupled to a flywheel.
Start the engine and the flywheel turn together. so this will be just below low threshold.
Im not sure yet at what engine rpm or rotations it will take to idle the engine turning the flywheel.
Thats why I need the be able to set the low threshold above engine idle.
Accelerate the throttle and time the run up to at high threshold number that was set.
Time from low threshold to high threshold in msec is what I what.

I am still not convinced you understand what I mean. You talked about 3000 and 13000. Are those RPM or counts of the number of times it has turned over?

the engine lets say idles at 2500 rpm. The flywheel will be turning 2500 rpm also
That's where i get the start 3000rpm to end 13000rpm
So i would think rpms

In that case what we have will not work. Suppose the engine is running at 3000 RPM and you start the counter, but leave the engine at 3000 RPM. In 1 minute the counter will get to 3000 and the function will start timing. Leave the engine at 3000RPM and in another 3 minutes and 20 seconds the counter will get to 13000 and will tell you that it has taken 200 seconds, but the engine is still at 3000 RPM.

once the engine is at idle say 2500rpm i start the test.
engine goes to Full throttle
the program starts its counts as the flywheel reaches 3000 counts
and runs until we see 13000 rotations. run finished.
the run should take less that 10 seconds