Skip to main content
deleted 251 characters in body
Source Link
user31481
user31481
case idle:
  if (voltageA0 > 1.0 || voltageA1 < 2.0 || voltageA2 > 3.5) {
     warningdigitalWrite(7, HIGH);
     if delay(voltageA0 > 1.05000) {
        theState = case1;
        }
;
    if digitalWrite(voltageA1 <7, 2.0LOW) {
       theState = case2;
       }
;
    if delay(voltageA2 > 3.50) {
    ;   theState = case3;
       }
   }

A more convoluted way:

case idle:
  bool volA0 =if (voltageA0 > 1.0;
  bool volA1 = voltageA1 < 2.0;
  bool volA2 = voltageA2 > 3.5;
  if (volA0 || volA1 || volA2) {
     warning();
     if (volA00) {
        theState = case1;
        }

    if (volA1voltageA1 < 2.0) {
       theState = case2;
       }

    if (volA2voltageA2 > 3.5) {
       theState = case3;
       }
   }
    

is probably a bit fasterEDIT: To clarify original answer, but it really depend onI inlined the compiler"warning" code and deleted the "case warning", as obviously this state is not longer needed.

case idle:
  if (voltageA0 > 1.0 || voltageA1 < 2.0 || voltageA2 > 3.5) {
     warning();
     if (voltageA0 > 1.0) {
        theState = case1;
        }

    if (voltageA1 < 2.0) {
       theState = case2;
       }

    if (voltageA2 > 3.5) {
       theState = case3;
       }
   }

A more convoluted way:

case idle:
  bool volA0 = voltageA0 > 1.0;
  bool volA1 = voltageA1 < 2.0;
  bool volA2 = voltageA2 > 3.5;
  if (volA0 || volA1 || volA2) {
     warning();
     if (volA0) {
        theState = case1;
        }

    if (volA1) {
       theState = case2;
       }

    if (volA2 > 3.5) {
       theState = case3;
       }
   }

is probably a bit faster, but it really depend on the compiler.

case idle:
  if (voltageA0 > 1.0 || voltageA1 < 2.0 || voltageA2 > 3.5) {
     digitalWrite(7, HIGH);
     delay(5000);
     digitalWrite(7, LOW);
     delay(0);     

     if (voltageA0 > 1.0) {
        theState = case1;
        }

    if (voltageA1 < 2.0) {
       theState = case2;
       }

    if (voltageA2 > 3.5) {
       theState = case3;
       }
   }
    

EDIT: To clarify original answer, I inlined the "warning" code and deleted the "case warning", as obviously this state is not longer needed.

Source Link
user31481
user31481

case idle:
  if (voltageA0 > 1.0 || voltageA1 < 2.0 || voltageA2 > 3.5) {
     warning();
     if (voltageA0 > 1.0) {
        theState = case1;
        }

    if (voltageA1 < 2.0) {
       theState = case2;
       }

    if (voltageA2 > 3.5) {
       theState = case3;
       }
   }

A more convoluted way:

case idle:
  bool volA0 = voltageA0 > 1.0;
  bool volA1 = voltageA1 < 2.0;
  bool volA2 = voltageA2 > 3.5;
  if (volA0 || volA1 || volA2) {
     warning();
     if (volA0) {
        theState = case1;
        }

    if (volA1) {
       theState = case2;
       }

    if (volA2 > 3.5) {
       theState = case3;
       }
   }

is probably a bit faster, but it really depend on the compiler.