Program always returning false and printing fail on lcd

Hello, good afternoon, hope we’ve been having lovely days, please, I’m writing a program for a switch socket tester, the program is to monitor the switching of the contacts, and it’ll be counting too the number of switching, if the contacts fail at any point, the program detects it and print fail on the lcd, while à buzzer buzzes, but, when I run the program, it just prints fail, and remains there, the code is below…

Thanks in advance

Fail_safe_detection_for_swiches_and_socket.ino (5.14 KB)

if (counting = true)

BONG !

Could that be the problem?

Ceejay90:
Could that be the problem?

It is not a problem if you want to set counting to true rather than testing whether it is true

It would be unusual to set a variable to a value in the conditional part of an if

Sorry, I don't understand

Ceejay90:
Sorry, I don't understand

Have you noticed that C++ has a "=" operator and a "==" operator?

Please, any more suggestions?

Clu4U

The assignment operator (=) is used to assign a value to a variable, element of an array, or property of an object.

The equality operator (==) is used to compare two values or expressions. It is used to compare numbers, strings, Boolean values, variables, objects, arrays, or functions. The result is TRUE if the expressions are equal and FALSE otherwise.

Have you corrected that if yet (most of them were o.k.so you should be able to see the difference)?

Here are a few more lines that look odd.

  digitalWrite(buzzer, OUTPUT); // what is the value of OUTPUT?
...
      else(linearValue = 1700);  // else statements don't normally look like this, what do you think it does?
...
        while (currentButtonState == LOW) {  // does anything in the while loop ever change currentButtonState?

I see the buzzer being switched on. Does anything ever switch it off?

Steve

Whoa, now that's a terrible mistake, the buzzer being high and I didn't link it with any value, noted, so, does that mean, if that is always high, the function will always run, even when I trigger other functions?

For the while loop, I've removed it

As you've made some changes please post the current version of your code and say what it is doing now.

Steve