Skip to content
Alex Krieg edited this page May 26, 2018 · 12 revisions

Functions

  • Button(int pinNr);
  • Button(int pinNr, unsigned int logicLevel);
  • ~Button();
  • void update();
  • void OnPressedEdge(void (*p_func)());
  • void OnReleasedEdge(void (*p_func)());
  • void OnBothButtonEdges(void (*p_func)());
  • void IsPressedHigh(void (*p_func)());
  • void IsPressedLow(void (*p_func)());
  • virtual boolean getValue();
  • int getPin();


Button(int pinNr);

Button(int pinNr, unsigned int logicLevel);

Description

  • Constructor
  • Needs a pinNr for the button
  • Can take logicLevel, default (no param) = activeHigh. If voltage rises up when the button is pressed, logicLevel = avtiveHigh
    If voltage falls when the button is pressed, logicLevel = activeLow
  • You can set the logicLevel as INPUT_PULLUP for the Arduino internal pullup resistor.

Syntax

Button myButton(3);
Button myButton(3,activeHigh);
Button myButton(3,activeLow);
Button myButton(3,INPUT_PULLUP);
Button myButton(3,pullup);
Button myButton(3,PULLUP);


~Button();

Description

  • Destructor

Syntax

delete &myButton;


void update();

Description

  • Reads the state of the button.
  • If any event Function is defined, it will run these in certain conditions.

Syntax

myButton.update();


Events

You do not know how events work?
Look over here

void OnPressedEdge(void (*p_func)());

  • Is executed when a rising edge of the button is detected.
  • NO values accepted.
  • NO return values.

void OnReleasedEdge(void (*p_func)());

  • Is executed when a falling edge of the button is detected.
  • NO values accepted.
  • NO return values.

void OnBothButtonEdges(void (*p_func)());

  • Is executed when a any edge of the button is detected.
  • NO values accepted.
  • NO return values.

void IsPressedHigh(void (*p_func)());

  • Is executed when the button is pressed.
  • NO values accepted.
  • NO return values.

void IsPressedLow(void (*p_func)());

  • Is executed when the button isn't pressed.
  • NO values accepted.
  • NO return values.

bool getValue();

Description

  • Returns the active state of the button pin.

Syntax

bool state = myButton.getValue();


int getPin();

Description

  • Returns the pin on which the button is connected to.

Syntax

int buttonPin = myButton.getPin();