You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
429 B

#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);
}
}