Go Down

Topic: Activating a TENS machine using a flex sensor (Read 20 times) previous topic - next topic

joeycampbell

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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy