when pulse is low?

hey there

I have a device which has 2 modes:

mode1: active
in this mode its pulses are 64ms HIGH and 3000ms LOW

mode2: deactive
in this mode the pulse is just low

how can I figure out that the device is deactive?
I read its pulse pin like so

          delay(3000);       //wait for 3s
  	     //do stuff for deactive mode


but I know it doesn't work as this delay doesn't necessary shows me the deactivate mode...

what should I do? note that I just cant use any timer

note that I just cant use any timer

Can you use a specific timer?
What does that even mean?

Look for edges.
What is your required response time?

Seems you don’t need to check timings, right? If you see a High then you know you are in mode 1

Do you want to know only at the start of the code? You could use an active wait or pulseIn() in the setup

If you need to monitor this all the time then either check during the loop (assuming it does not take more than 64ms) or attach an interrupt pin to the signal and trigger upon a low to high transition

note that I just cant use any timer


-jim lee

I can't use timer but if I could what was the solution?

Using some sort of time reference? I’d start out like this…

#include <timeObj.h>

timeObj  timeout(3000); // Timer set to 3 seconds. Maybe set for smidge longer?
bool     active;        // Our state variable. Saves if things are active or non active.

void setup() {

   active = false;   // Npt seen a pulse so we'll say, non active. (false)


// Is this pulse high or low?
bool readState() {  

   bool highLow;
   //fill this part in..
   // Is CURRENT input state high (true)? or low (false)?
   return highLow;

void loop(void) {

   if (readState()) {               // If the pulse is high..
      active = true;                // Then it must be active.
      timeout.start();              // And we'll restart the timeout timer.
   if (timeout.ding()) {            // If we've seen only a low pulse for 3000 or so ms..
      active = false;               //  Then we are no longer active.
   if (active) {                    // If, (after doing the checks) the state is active..
                                    //do an active thing..
   } else {                         // Else, (after doing the checks) the state is non-active.. 
                                    // do a non-active thing..

You’ll need to fill out the readState() function and install LC_baseTools from the IDE library manager to try it.

Good luck!

-jim lee

Your device is 'deactive' when the time since the last HIGH pulse has been a little greater than 3000 milliseconds.

unsigned long LastTimeKeyWasHIGH  = 0;
void setup()
  pinMode(key, INPUT);
void loop()
  if (digitalRead(key))
    LastTimeKeyWasHIGH = millis();

  if (millis() - LastTimeKeyWasHIGH > 3100)
    // DEACTIVE!