Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 1c424fc

Browse files
Criar biblioteca para simplificar a leitura dos botões
1 parent 8cc6dd4 commit 1c424fc

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "RisingEdgeButton.h"
2+
3+
RisingEdgeButton::RisingEdgeButton()
4+
{
5+
}
6+
7+
RisingEdgeButton::RisingEdgeButton(const int pin)
8+
{
9+
this->setPin(pin);
10+
}
11+
12+
void RisingEdgeButton::setPin(const int pin)
13+
{
14+
this->pin = pin;
15+
}
16+
17+
bool RisingEdgeButton::pressed()
18+
{
19+
return this->read() && this->state == HIGH;
20+
}
21+
22+
bool RisingEdgeButton::read()
23+
{
24+
int newState = digitalRead(this->pin);
25+
bool changed = false;
26+
27+
if (newState != this->state) {
28+
this->state = newState;
29+
changed = true;
30+
}
31+
32+
return changed;
33+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef PLACARDUINO_RISING_EDGE_BUTTON_H
2+
#define PLACARDUINO_RISING_EDGE_BUTTON_H
3+
4+
#include <Arduino.h>
5+
6+
class RisingEdgeButton
7+
{
8+
public:
9+
RisingEdgeButton();
10+
RisingEdgeButton(const int pin);
11+
12+
void setPin(const int pin);
13+
bool pressed();
14+
15+
private:
16+
int pin;
17+
int state = LOW;
18+
19+
bool read();
20+
};
21+
22+
#endif // PLACARDUINO_RISING_EDGE_BUTTON_H

0 commit comments

Comments
 (0)