Logically defining the timings

Hello all!

I am obtaining sensor values and according to certain value the time is measured.
To make things simple the above and below certain level is only considered.
This is done via the switch:


  switch (currentState) {
    case WAITING_ABOVE:
      if (OS > HT) {
        belowHT = 0;
        belowHT += currentTime - startTime;
        startTime = currentTime;
        currentState = WAITING_BELOW;
      }
      break;
    case WAITING_BELOW:
      if (OS < HT) {
        aboveHT = 0;
        aboveHT += currentTime - startTime;
        startTime = currentTime;
        currentState = WAITING_ABOVE;
      }
      break;
  }

In addition, the "state machine" is used in the setup:

  // *** using state machine for measuring time of sensor level ***
  if (Sensor.getData() > HT) {
    currentState = WAITING_BELOW;
  }
  else {
    currentState = WAITING_ABOVE;
  }
  // *** end of using state machine for measuring time of sensor level ***

In the main loop() I can easily observe the measurements and the so-called "individual level measurement pattern", for example a simple below and above pattern looks like this "eeeTTTeee" can be easily spotted, found with the

if(aboveHT>300 and belowHT>1000) {
// toggle the var
}

So far so good, BUT, if I want to found, spot a more complex pattern, something like two consecutive measurements, something like this "eeeTTTeTTTeee" it gets tricky, for example, I do not need the information about the 1st pattern, but only the last, or the next one, etc.
Eventually the idea is to recognise the pattern...

Any ideas how to tackle this problem?

best.

You should post your complete sketch.

Q: "Why should I post my complete sketch, when this is the only area with the problem?"
A: "So we do not need to ask you to post your complete sketch."

See also: GIGO

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.