Skip to content

Commit

Permalink
Criar biblioteca para simplificar a leitura dos botões
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoweiland committed Jan 14, 2018
1 parent 8cc6dd4 commit 1c424fc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/RisingEdgeButton/RisingEdgeButton.cpp
@@ -0,0 +1,33 @@
#include "RisingEdgeButton.h"

RisingEdgeButton::RisingEdgeButton()
{
}

RisingEdgeButton::RisingEdgeButton(const int pin)
{
this->setPin(pin);
}

void RisingEdgeButton::setPin(const int pin)
{
this->pin = pin;
}

bool RisingEdgeButton::pressed()
{
return this->read() && this->state == HIGH;
}

bool RisingEdgeButton::read()
{
int newState = digitalRead(this->pin);
bool changed = false;

if (newState != this->state) {
this->state = newState;
changed = true;
}

return changed;
}
22 changes: 22 additions & 0 deletions lib/RisingEdgeButton/RisingEdgeButton.h
@@ -0,0 +1,22 @@
#ifndef PLACARDUINO_RISING_EDGE_BUTTON_H
#define PLACARDUINO_RISING_EDGE_BUTTON_H

#include <Arduino.h>

class RisingEdgeButton
{
public:
RisingEdgeButton();
RisingEdgeButton(const int pin);

void setPin(const int pin);
bool pressed();

private:
int pin;
int state = LOW;

bool read();
};

#endif // PLACARDUINO_RISING_EDGE_BUTTON_H

0 comments on commit 1c424fc

Please sign in to comment.