Permalink
Browse files

Criar biblioteca para simplificar a leitura dos botões

  • Loading branch information...
eduardoweiland committed Jan 13, 2018
1 parent 8cc6dd4 commit 1c424fc206babfc5e2fb2fcf794144af379810cc
Showing with 55 additions and 0 deletions.
  1. +33 −0 lib/RisingEdgeButton/RisingEdgeButton.cpp
  2. +22 −0 lib/RisingEdgeButton/RisingEdgeButton.h
@@ -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;
}
@@ -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.