Understanding a boolean function

Hi,

The below first sketch works but the second (which is a modification of the first), doesn’t.

I cannot understand why the Boolean function isn’t returning the correct state.

The idea behind it is the turn on the led when motion is detected by the sensor.

Any help is appreciated.
TIA

const int ledPin = 13;
const int vibroPin = 3;

void setup() {
  pinMode(vibroPin, INPUT);
  pinMode(ledPin, OUTPUT);  // test use only
}

void loop() {
  vibrationCheck ();
}

void vibrationCheck() {
  long measurement;
  measurement = pulseIn (vibroPin, HIGH); //wait for the pin to get HIGH and returns measurement
  if (measurement > 1000) digitalWrite(ledPin, HIGH);
  else digitalWrite(ledPin, LOW);
  delay(50);
}
const int ledPin = 13;
const int vibroPin = 3;

void setup() {
  pinMode(vibroPin, INPUT);
  pinMode(ledPin, OUTPUT);  // test use only
}

void loop() {
  if (vibrationCheck) digitalWrite(ledPin, HIGH);
  else digitalWrite(ledPin, LOW);
}

bool vibrationCheck() {
  long measurement;
  measurement = pulseIn (vibroPin, HIGH); //wait for the pin to get HIGH and returns measurement
  if (measurement > 1000) return true;
  else return false;
  delay(50);
}

One thing is that your delay is never executed in the second.

That's true but I don´t think is the problem.

You're never calling the function :wink: Calling a function would include ().

Yessir!! a minor detal :slight_smile:
Thank you.

A function without brackets is treated as a pointer to the function code.