Style sweep

This commit is contained in:
fvanroie 2020-02-21 21:48:06 +01:00
parent cdcc127a26
commit dfde8c79ba

View File

@ -1,20 +1,15 @@
/*
Button - a small library for Arduino to handle button debouncing
MIT licensed.
*/
#include "Button.h"
#include <Arduino.h>
Button::Button(uint8_t pin)
: _pin(pin)
, _delay(500)
, _state(HIGH)
, _ignore_until(0)
, _has_changed(false)
{
}
Button::Button(uint8_t pin) : _pin(pin), _delay(100), _state(HIGH), _ignore_until(0), _has_changed(false)
{}
void Button::begin()
{
@ -28,14 +23,12 @@ void Button::begin()
bool Button::read()
{
// ignore pin changes until after this delay time
if (_ignore_until > millis())
{
if(_ignore_until > millis()) {
// ignore any changes during this period
}
// pin has changed
else if (digitalRead(_pin) != _state)
{
else if(digitalRead(_pin) != _state) {
_ignore_until = millis() + _delay;
_state = !_state;
_has_changed = true;
@ -54,8 +47,7 @@ bool Button::toggled()
// mostly internal, tells you if a button has changed after calling the read() function
bool Button::has_changed()
{
if (_has_changed == true)
{
if(_has_changed == true) {
_has_changed = false;
return true;
}