Activating a TENS machine using a flex sensor

Hi I have a Unity video game controlled using a flex sensor - when the user flex's their bicep the character moves forward. I want to activate a TENS machine when the user collects certain objects in the game. I have this working.....the problem is I want to activate the TENS machine for 1000ms and then deactivate it. I can activate/deactivate the TENS machine from the game engine via the serial port my issue is with the DELAY function. When I use the DELAY function it causes a glitch or pause in the game play....as a work around I tried using the function below, it would activate the TENS but it would not deactivate it.

#include <elapsedMillis.h>
#define interval 1000
elapsedMillis timeElapsed;

void triggertens()
{
digitalWrite(TENS, HIGH);
if (timeElapsed > interval) {
timeElapsed -= interval; //reset the timer
digitalWrite(TENS, LOW);}
}

What does work is a WHILE LOOP however this also causes a glitch similar to the DELAY:

void triggertens()
{
elapsedMillis timeElapsed;
while (timeElapsed < interval)
{
digitalWrite(TENS, HIGH);
}
digitalWrite(TENS, LOW);
timeElapsed = 0;
}

Any advice would be great.