RBE1001Lib
src
button.h
Go to the documentation of this file.
1
//
2
// button.h
3
//
4
//
5
// Created by Gregory C Lewin on 2/20/17.
6
//
7
//
8
9
/*
10
* A simple button class with polling. Uses 'proper' debouncing with non-blocking timer
11
*/
12
13
#ifndef BUTTON_H
14
#define BUTTON_H
15
16
#include <Arduino.h>
17
18
class
Button
19
{
20
private
:
21
enum
BUTTON_STATE
{
BUTTON_STABLE
,
BUTTON_UNSTABLE
};
22
BUTTON_STATE
state
=
BUTTON_STABLE
;
23
24
uint8_t
buttonPin
= -1;
25
uint8_t
activeState
= LOW;
//active LOW by default
26
27
uint8_t
stabButtonPos
= HIGH;
//most recent stable position
28
uint8_t
tempButtonPos
= HIGH;
//temporary position, may fluctuate due to bouncing
29
30
uint32_t
lastBounceTime
= 0;
31
uint32_t
debouncePeriod
= 10;
// in ms
32
33
public
:
34
Button
(uint8_t
pin
, uint32_t db = 10);
35
void
Init
(
bool
usePullup =
true
);
36
bool
CheckButtonPress
(
void
);
37
};
38
39
#endif
/* button_h */
Button
Definition:
button.h:18
Button::CheckButtonPress
bool CheckButtonPress(void)
Definition:
button.cpp:17
Button::debouncePeriod
uint32_t debouncePeriod
Definition:
button.h:31
Button::BUTTON_UNSTABLE
Definition:
button.h:21
Button::stabButtonPos
uint8_t stabButtonPos
Definition:
button.h:27
Button::BUTTON_STATE
BUTTON_STATE
Definition:
button.h:21
Button::Init
void Init(bool usePullup=true)
Definition:
button.cpp:9
Button::state
BUTTON_STATE state
Definition:
button.h:22
Button::tempButtonPos
uint8_t tempButtonPos
Definition:
button.h:28
Button::buttonPin
uint8_t buttonPin
Definition:
button.h:24
Button::BUTTON_STABLE
Definition:
button.h:21
Button::lastBounceTime
uint32_t lastBounceTime
Definition:
button.h:30
pin
int pin
Definition:
ToneExample.ino:7
Button::Button
Button(uint8_t pin, uint32_t db=10)
Definition:
button.cpp:3
Button::activeState
uint8_t activeState
Definition:
button.h:25
Generated by
1.8.13