Go Down

Topic: Understanding a boolean function (Read 103 times) previous topic - next topic

ebolisa

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

Code: [Select]

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);
}


Code: [Select]

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);
}

KeithRB

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

ebolisa

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

septillion

You're never calling the function ;) Calling a function would include ().
Use fricking code tags!!!!
I want x => I would like x
I need help => I would like help
Need fast => Go and pay someone to do the job...

ebolisa

#4
May 17, 2016, 09:47 pm Last Edit: May 17, 2016, 09:56 pm by ebolisa
Yessir!! a minor detal  :)
Thank you.

aarg

A function without brackets is treated as a pointer to the function code.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy