HomeWaterLeaksDetection
Button Class Reference

#include <Button.h>

Public Member Functions

 Button (int pin)
 Constructor of the class. More...
 
int isPressed ()
 Tests if the button is being pressed. More...
 

Private Attributes

int pin
 number of the pin the button si connected to More...
 
int currentInputValue
 current state of the input pin More...
 
int previousInputValue
 previous state of the input pin More...
 

Detailed Description

Author
silhavyj A17B0362P

This class sepresents the reset button the user is required to press after a water leak has been detected of they want to reset the device.

Definition at line 13 of file Button.h.

Constructor & Destructor Documentation

◆ Button()

Button::Button ( int  pin)

Constructor of the class.

Parameters
pinnumber of the pin the button si connected to

Definition at line 3 of file Button.cpp.

3  {
4  this->pin = pin;
5 
8 }

References currentInputValue, pin, and previousInputValue.

Member Function Documentation

◆ isPressed()

int Button::isPressed ( )

Tests if the button is being pressed.

It reads the state of the input pin if it has gone from LOW to HIGH, the method will return 1 as the button is being pressed.

Returns
1 if the button is being pressed. Otherwise, 0.

Definition at line 10 of file Button.cpp.

10  {
11  int state = LOW;
12  currentInputValue = digitalRead(pin);
13 
14  if (currentInputValue == HIGH && previousInputValue == LOW)
15  state = HIGH;
16 
18  return state;
19 }

References currentInputValue, pin, and previousInputValue.

Referenced by LeaksController::update().

Member Data Documentation

◆ currentInputValue

int Button::currentInputValue
private

current state of the input pin

Definition at line 18 of file Button.h.

Referenced by Button(), and isPressed().

◆ pin

int Button::pin
private

number of the pin the button si connected to

Definition at line 17 of file Button.h.

Referenced by Button(), and isPressed().

◆ previousInputValue

int Button::previousInputValue
private

previous state of the input pin

Definition at line 19 of file Button.h.

Referenced by Button(), and isPressed().


The documentation for this class was generated from the following files:
Button::currentInputValue
int currentInputValue
current state of the input pin
Definition: Button.h:18
Button::pin
int pin
number of the pin the button si connected to
Definition: Button.h:17
Button::previousInputValue
int previousInputValue
previous state of the input pin
Definition: Button.h:19