wordclock/libraries/Button/Button.cpp

33 lines
429 B
C++
Raw Permalink Normal View History

2019-02-13 19:27:22 +01:00
#include <Arduino.h>
#include <Wire.h>
#include "Button.h"
Button::Button(uint8_t _pin, uint8_t _mode)
{
pin = _pin;
mode = _mode;
}
void Button::begin()
{
if (mode == LOW)
{
pinMode(pin, INPUT_PULLUP);
}
else if (mode == HIGH)
{
pinMode(pin, INPUT);
}
}
void Button::loop(ButtonCallbackFunction callback)
{
if (digitalRead(pin) == mode)
{
(*callback)();
// debounce
delay(250);
}
}