Skip to content

IR_sensor

Alex Krieg edited this page Jun 13, 2018 · 4 revisions

Hardware

Functions

  • IR_sensor(byte IR_ledPin,byte IR_pdPin);
  • ~IR_sensor();
  • void update();
  • byte ledPin();
  • byte pdPin();
  • void highTriggerValue(unsigned int triggerValue);
  • unsigned int highTriggerValue();
  • void lowTriggerValue(unsigned int triggerValue);
  • unsigned int lowTriggerValue();
  • void triggerHysteresis(unsigned int hysteresis);
  • unsigned int triggerHysteresis();
  • unsigned int value();
  • void onLowTrigger(void (*p_func)());
  • void onLowTrigger(void (*p_func)(),unsigned int triggerValue);
  • void onHighTrigger(void (*p_func)());
  • void onHighTrigger(void (*p_func)(),unsigned int triggerValue);
  • void onBothTrigger(void (*p_func)());


IR_sensor(byte IR_ledPin,byte IR_pdPin);

Description

  • Constructor of the sensor
  • Parameters are IR_ledPin and IR_pdPin
  • IR_ledPin is the pin on which the IR-Led is connected to.
  • IR_pdPin is the analog input on which the IR-photodiode is connected to.

Syntax

IR_sensor mySensor(2,A0);


~IR_sensor();

Description

  • Destructor

Syntax

delete &mySensor;


void update();

Description

  • Reads the sensor value.
  • Triggeres the events

Syntax

mySensor.update();


byte ledPin();

Description

  • Gets the pin of the IR-led back.

Syntax

byte pin = mySensor.ledPin();


byte pdPin();

Description

  • Gets the pin of the IR-photodiode back.

Syntax

byte pin = mySensor.pdPin();


void highTriggerValue(unsigned int triggerValue);

Description

  • Sets the trigger point for the onHighTrigger event.

Syntax

mySensor.highTriggerValue(800);


unsigned int highTriggerValue();

Description

  • Gets the trigger point for the onHighTrigger event.

Syntax

unsigned int triggPoint = mySensor.highTriggerValue();


void lowTriggerValue(unsigned int triggerValue);

Description

  • Sets the trigger point for the onLowTrigger event.

Syntax

mySensor.lowTriggerValue(1000);


unsigned int lowTriggerValue();

Description

  • Gets the trigger point for the onLowTrigger event.

Syntax

unsigned int triggPoint = mySensor.lowTriggerValue();


void triggerHysteresis(unsigned int hysteresis);

Description

  • Sets the hysteresis for the events.

Syntax

mySensor.triggerHysteresis(30);


unsigned int triggerHysteresis();

Description

  • Gets the hysteresis for the events.

Syntax

unsigned int hysteresis= mySensor.triggerHysteresis();


unsigned int value();

Description

  • Gets the current value of the IR-photodiode pin.

Syntax

unsigned int value = mySensor.value();


Events

You do not know how events work?
Look over here

void onLowTrigger(void (*p_func)());

void onLowTrigger(void (*p_func)(),unsigned int triggerValue);

  • Is executed when the IR-light is no longer detected and the signal is above triggerValue.
  • NO value accepted.
  • NO return values.

void onHighTrigger(void (*p_func)());

void onHighTrigger(void (*p_func)(),unsigned int triggerValue);

  • Is executed when the IR-light is detected and the signal is below triggerValue.
  • NO value accepted.
  • NO return values.

void onBothTrigger(void (*p_func)());

  • Is executed when onLowTrigger or onHighTrigger is executed.
  • NO value accepted.
  • NO return values.